ID:               40064
 Updated by:       [EMAIL PROTECTED]
 Reported By:      christoph at ziegenberg dot de
-Status:           Open
+Status:           Bogus
 Bug Type:         PDO related
 Operating System: Windows XP SP2
 PHP Version:      5.2.0
 New Comment:

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

That's what sqlite returns as field name, PDO/PHP don't change that but
use what the library provides.


Previous Comments:
------------------------------------------------------------------------

[2007-01-08 14:20:11] christoph at ziegenberg dot de

Description:
------------
If you get the data of a query like "SELECT tablealias.fieldname FROM
table tablealias.fieldname GROUP BY tablealias.fieldname" the result
array contains not only the field name, but also the table alias name
as field name.

Only using "SELECT tablealias.fieldname AS fieldname..." fixes this
problem, but this should not be neccessary.

I don't know if this is a PDO or SQLite problem.

Reproduce code:
---------------
<?php
$sldb = new PDO('sqlite:memory');
$sldb->query("CREATE TABLE test (id INTEGER PRIMARY KEY
AUTOINCREMENT)");
$sldb->query("INSERT INTO test (id) VALUES (1)");

$queries = array();
$queries[] = "SELECT id FROM test";
$queries[] = "SELECT t1.id FROM test t1";
$queries[] = "SELECT t1.id FROM test t1 GROUP BY t1.id";
$queries[] = "SELECT t1.id AS id FROM test t1 GROUP BY t1.id";

foreach ($queries as $query)
{
    $stmt = $sldb->prepare($query);
    $stmt->execute();
    
    if ($row = $stmt->fetch(PDO::FETCH_ASSOC))
    {
        echo 'result for query "' . $query . '":<br />';
        print_r($row);
        echo '<br /><br />';
    }
}
?>

Expected result:
----------------
result for query "SELECT id FROM test":
Array ( [id] => 1 )

result for query "SELECT t1.id FROM test t1":
Array ( [id] => 1 )

result for query "SELECT t1.id FROM test t1 GROUP BY t1.id":
Array ( [id] => 1 )

result for query "SELECT t1.id AS id FROM test t1 GROUP BY t1.id":
Array ( [id] => 1 ) 

Actual result:
--------------
result for query "SELECT id FROM test":
Array ( [id] => 1 )

result for query "SELECT t1.id FROM test t1":
Array ( [id] => 1 )

result for query "SELECT t1.id FROM test t1 GROUP BY t1.id":
Array ( [t1.id] => 1 )

result for query "SELECT t1.id AS id FROM test t1 GROUP BY t1.id":
Array ( [id] => 1 ) 


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=40064&edit=1

Reply via email to