From:             uwendel at mysql dot com
Operating system: 
PHP version:      5.3CVS-2008-03-07 (CVS)
PHP Bug Type:     PDO related
Bug description:  fetchAll(PDO::FETCH_COLUMN|<other>, ...) and column index 
-1/PHP_INT_MAX + 1

Description:
------------
Under certain circumstances  fetchAll  ([ int $fetch_style  [, int
$column_index  [, array $ctor_args  ]]] ) seems not to recognize invalid
column index specifications. It seems a bit like an INT overflow to me. The
issue can be observed when using PDO::FETCH_COLUMN together with another
flag like PDO::FETCH_UNIQUE or PDO::FETCH_GROUP.

SELECT id, grp FROM test
-> column indicies are:
   id:  0
   grp: 1

fetchAll(PDO::FETCH_COLUMN, 2)  -> Warning as expected -> OK
fetchAll(PDO::FETCH_COLUMN, -1) -> Warning as expected -> OK

fetchAll(PDO::FETCH_GROUP|PDO::FETCH_COLUMN, -1) -> No warning -> Bug?
fetchAll(PDO::FETCH_GROUP|PDO::FETCH_COLUMN, PHP_INT_MAX + 1) -> No
warning -> Bug?
fetchAll(PDO::FETCH_GROUP|PDO::FETCH_COLUMN, 2) -> Warning -> OK


fetchAll(PDO::FETCH_UNIQUE|PDO::FETCH_COLUMN, -1) -> No warning -> Bug?
fetchAll(PDO::FETCH_UNIQUE|PDO::FETCH_COLUMN, PHP_INT_MAX + 1) -> No
warning -> Bug?
fetchAll(PDO::FETCH_UNIQUE|PDO::FETCH_COLUMN, 2) -> Warning -> OK



Reproduce code:
---------------
--- example using PDO_MYSQL -------

 sapi/cli/php -r '$db = new
PDO("mysql:dbname=phptest;unix_socket=/tmp/mysql.sock", "root", "root");
$db->exec("DROP TABLE test"); $db->exec("CREATE TABLE test (id INT, grp
CHAR(1))"); $db->exec("INSERT INTO test(id, grp) VALUES (5, \"A\")");
$db->exec("INSERT INTO test(id, grp) VALUES (6, \"B\")"); $stmt =
$db->prepare("SELECT id, grp FROM test ORDER BY id ASC"); $stmt->execute();
var_dump($stmt->fetchAll(PDO::FETCH_COLUMN, -1)); $stmt->execute();
var_dump($stmt->fetchAll(PDO::FETCH_GROUP|PDO::FETCH_COLUMN, -1));
$stmt->execute();
var_dump($stmt->fetchAll(PDO::FETCH_GROUP|PDO::FETCH_COLUMN, PHP_INT_MAX +
1));'

Warning: PDOStatement::fetchAll(): SQLSTATE[HY000]: General error: Invalid
column index in Command line code on line 1
array(0) {
}
array(2) {
  [5]=>
  array(1) {
    [0]=>
    string(1) "A"
  }
  [6]=>
  array(1) {
    [0]=>
    string(1) "B"
  }
}
array(2) {
  [5]=>
  array(1) {
    [0]=>
    string(1) "A"
  }
  [6]=>
  array(1) {
    [0]=>
    string(1) "B"
  }
}


---------- example using PDO_SQlite -----------

[EMAIL PROTECTED]:~/php53_libmysql> sapi/cli/php -r '$db = new
PDO("sqlite:/tmp/foo"); $db->exec("DROP TABLE test"); $db->exec("CREATE
TABLE test (id INT, grp CHAR(1))"); $db->exec("INSERT INTO test(id, grp)
VALUES (5, \"A\")"); $db->exec("INSERT INTO test(id, grp) VALUES (6,
\"B\")"); $stmt = $db->prepare("SELECT id, grp FROM test ORDER BY id ASC");
$stmt->execute(); var_dump($stmt->fetchAll(PDO::FETCH_COLUMN, -1));
$stmt->execute();
var_dump($stmt->fetchAll(PDO::FETCH_UNIQUE|PDO::FETCH_COLUMN, -1));
$stmt->execute();
var_dump($stmt->fetchAll(PDO::FETCH_UNIQUE|PDO::FETCH_COLUMN, PHP_INT_MAX +
1)); $stmt->execute();
var_dump($stmt->fetchAll(PDO::FETCH_UNIQUE|PDO::FETCH_COLUMN, 2));'

Warning: PDOStatement::fetchAll(): SQLSTATE[HY000]: General error: Invalid
column index in Command line code on line 1
array(0) {
}
array(2) {
  [5]=>
  string(1) "A"
  [6]=>
  string(1) "B"
}
array(2) {
  [5]=>
  string(1) "A"
  [6]=>
  string(1) "B"
}

Warning: PDOStatement::fetchAll(): SQLSTATE[HY000]: General error: Invalid
column index in Command line code on line 1
array(0) {
}


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

Reply via email to