ID:               44190
 Updated by:       [EMAIL PROTECTED]
 Reported By:      uwendel at mysql dot com
-Status:           Open
+Status:           Bogus
 Bug Type:         PDO related
 Operating System: Linux 64
 PHP Version:      5.3CVS-2008-02-20 (CVS)
 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

The name of the column conflicts with numeric indexes.


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

[2008-02-20 19:01:13] uwendel at mysql dot com

Description:
------------
"PDO::FETCH_BOTH (default): returns an array indexed by both column
name and 0-indexed column number as returned in your result set",
http://de.php.net/manual/en/function.PDOStatement-fetch.php

[1] This looks like a wrong result for PDO::FETCH_BOTH to me: 

 SELECT 1 -> 
 array(1 => "1", 2 => "2")

Looks as if PDO uses the "1" as an index offset and does not start the
column numbering at 0 but at "1". 

[2] Try the same with SELECT 2 and you see what I mean:

 SELECT 2 ->
 array(2 => "2", 3 => "2")

I'd rather expect something like:

 SELECT 1 ->
 array(0 => "1", 1 => "1")

Or in pseudo-code:

 FETCH::BOTH == array_merge(FETCH::ASSOC, FETCH_NUM)









Reproduce code:
---------------
[1] LD_LIBRARY_PATH=/usr/lib/oracle/10.2.0.3/client/lib sapi/cli/php -r
'$pdo=new PDO("oci:dbname=//localhost:1521/XE", "SYSTEM", "oracle");
var_dump($pdo->query("SELECT 1 FROM DUAL")->fetch(PDO::FETCH_BOTH));'
array(2) {
  [1]=>
  string(1) "1"
  [2]=>
  string(1) "1"
}

[2] [EMAIL PROTECTED]:~/php53>
LD_LIBRARY_PATH=/usr/lib/oracle/10.2.0.3/client/lib sapi/cli/php -r
'$pdo=new PDO("sqlite:/tmp/foo.db"); var_dump($pdo->query("SELECT
2")->fetch(PDO::FETCH_BOTH));'
array(2) {
  [2]=>
  string(1) "2"
  [3]=>
  string(1) "2"
}



This is my failing MySQL test, don't know if its for use of you.
Someone would need to port it to all other drivers to make it useful.

--TEST--
MySQL PDOStatement->fetch()
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('mysql_pdo_test.inc');
MySQLPDOTest::skip();
$db = MySQLPDOTest::factory();
?>
--FILE--
<?php
        require_once('mysql_pdo_test.inc');
        $db = MySQLPDOTest::factory();

        function fetch($offset, &$db, $query, $expect = null) {

                try {
                        $stmt = $db->query('SELECT 1');
                        $num = $stmt->fetch(PDO::FETCH_NUM);

                        $stmt = $db->query('SELECT 1');
                        $assoc = $stmt->fetch(PDO::FETCH_ASSOC);

                        $stmt = $db->query('SELECT 1');
                        $both = $stmt->fetch(PDO::FETCH_BOTH);

                        $computed_both = array_merge($num, $assoc);
                        if ($computed_both != $both) {
                                printf("[%03d] Suspicious FETCH_BOTH result, 
dumping\n", $offset);
                                var_dump($computed_both);
                                var_dump($both);
                        }

                        if (!is_null($expect) && ($expect != $both)) {
                                printf("[%03d] Expected differes from returned 
data, dumping\n",
$offset);
                                var_dump($expect);
                                var_dump($both);
                        }

                } catch (PDOException $e) {

                        printf("[%03d] %s, [%s] %s\n",
                                $offset,
                                $e->getMessage(), $db->errroCode(), implode(' ',
$db->errorInfo()));

                }

        }

        try {

                fetch(2, &$db, 'SELECT 1', array(0 => '1', '1' => '1'));

        } catch (PDOException $e) {
                printf("[001] %s [%s] %s\n",
                        $e->getMessage(), $db->errorCode(), implode(' ',
$db->errorInfo()));
        }
        print "done!";
--BUGFREE_EXPECTF--
done!
--EXPECTF--
[002] Suspicious FETCH_BOTH result, dumping
array(2) {
  [0]=>
  string(1) "1"
  [1]=>
  string(1) "1"
}
array(2) {
  [1]=>
  string(1) "1"
  [2]=>
  string(1) "1"
}
[002] Expected differes from returned data, dumping
array(2) {
  [0]=>
  string(1) "1"
  [1]=>
  string(1) "1"
}
array(2) {
  [1]=>
  string(1) "1"
  [2]=>
  string(1) "1"
}
done!



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


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

Reply via email to