From:             uwendel at mysql dot com
Operating system: Linux 64
PHP version:      5.3CVS-2008-02-20 (CVS)
PHP Bug Type:     PDO related
Bug description:  SELECT 1 and PDO::FETCH_BOTH 

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 bug report at http://bugs.php.net/?id=44190&edit=1
-- 
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=44190&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): 
http://bugs.php.net/fix.php?id=44190&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=44190&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=44190&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=44190&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=44190&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=44190&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=44190&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=44190&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=44190&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=44190&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=44190&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=44190&r=globals
PHP 4 support discontinued:   http://bugs.php.net/fix.php?id=44190&r=php4
Daylight Savings:             http://bugs.php.net/fix.php?id=44190&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=44190&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=44190&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=44190&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=44190&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=44190&r=mysqlcfg

Reply via email to