php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44171 PDO->query ('SELECT ...', PDO::FETCH_COLUMN, -1) - error or not?
Submitted: 2008-02-19 14:56 UTC Modified: 2008-02-20 03:12 UTC
From: uwendel at mysql dot com Assigned:
Status: Closed Package: PDO related
PHP Version: 5.3CVS-2008-02-19 (CVS) OS: Linux
Private report: No CVE-ID: None
 [2008-02-19 14:56 UTC] uwendel at mysql dot com
Description:
------------
What is PDO->query('SELECT ...', PDO::FETCH_COLUMN, $colno) supposed to do if you pass an invalid column number in $colno, e.g.:

$stmt = $pdo->query('SELECT only_column FROM test', PDO::FETCH_COLUMN, -1);

My preference would be to make PDO bail about the invalid offset. However, I do not know if this would work with all drivers. So, maybe its even technically not possible to make PDO emit a warning if the requested column is not available.

In any case, I ask to update the manual and tell people about this edge case.


Reproduce code:
---------------
nixnutz@ulflinux:~/php53> sapi/cli/php -r '$pdo=new PDO("sqlite:/tmp/foo.db"); @$pdo->exec("DROP TABLE test"); $pdo->exec("CREATE TABLE test(id INT)"); $pdo->exec("INSERT INTO test(id) VALUES (1)"); var_dump($pdo->query("SELECT id FROM test", PDO::FETCH_COLUMN, -1)->fetchAll());'
array(0) {
}

(Same with MySQL)

Expected result:
----------------
If possible, make PDO bail out when calling query() with invalid column offsets. If that's not possible for technical reasons, please consider having a note about this in the manual.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-02-20 03:12 UTC] iliaa@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Nov 23 08:01:28 2024 UTC