php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52104 bindColumn creates Warning regardless of ATTR_ERRMODE settings
Submitted: 2010-06-16 22:47 UTC Modified: 2011-06-01 15:23 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: daniel dot baulig at gmx dot de Assigned: iliaa (profile)
Status: Closed Package: PDO related
PHP Version: 5.3.2 OS: Windows 7 / Debian
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: daniel dot baulig at gmx dot de
New email:
PHP Version: OS:

 

 [2010-06-16 22:47 UTC] daniel dot baulig at gmx dot de
Description:
------------
If you call bindColumn on a non existent column it will always create a warning, no matter how the PDO object is configured to respond to errors (ERRMODE_EXCEPTION, ERRMODE_SILENT, ERRMODE_WARNING).

I actually recreated this on PHP 5.3.1 and PHP 5.2.6-1+lenny8 (from Debian Lenny repository) and have NOT tried it on 5.3.2. Since I was not able to find any references for this bug on the web, I believe I might be the first one to encounter it and it is propably not fixed as of PHP 5.3.2

Test script:
---------------
$pdo = new PDO('mysql:host=localhost;dbname=db', 'root', '');
$pdo->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$statement = $pdo->prepare('SELECT id FROM aTable');
$statement->execute();

$field= NULL;

try
{
   $statement->bindColumn('none_existent_field', $field, PDO::PARAM_INT);

   while ($statement->fetch( PDO::FETCH_BOUND ))
   {
      echo $field. "<br/>\n";
   }
}
catch (PDOException $e)
{
   echo "Database field not in result set!<br/>\n";
}

Expected result:
----------------
The string "Database field not in result set!<br/>\n";

Actual result:
--------------
A warning:
<b>Warning</b>:  PDOStatement::bindColumn() [<a href='pdostatement.bindcolumn'>pdostatement.bindcolumn</a>]: Did not found column name 'none_existent_field' in the defined columns; it will not be bound in <b>/path/to/script.php</b> on line <b>10</b><br />


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-06-16 23:07 UTC] daniel dot baulig at gmx dot de
I looked into 5.3 SVN source code and was able to spot the problem. The following line is causing the Warning:

php_error_docref(NULL TSRMLS_CC, E_WARNING, "Did not found column name '%s' in the defined columns; it will not be bound", param->name);

I believe it should be replaced by something like the following:
pdo_raise_impl_error(stmt->dbh, stmt, "?????", "Did not found column name in the defined columns; it will not be bound" TSRMLS_CC);

I also believe "Did not found column name" is not proper english and should either be "Did not find column name" or "Column name not found". I also do not know the exact meaning of the error codes used in other pdo_raise_impl_error like "HY093", so an appropriate errorcode for this error should be inserted instead of the question marks.
 [2010-06-16 23:12 UTC] daniel dot baulig at gmx dot de
This code ofcourse resides in /ext/pdo/pdo_stmt.c
 [2010-06-18 04:50 UTC] kalle@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: kalle
 [2010-06-18 04:50 UTC] kalle@php.net
Ill have a look at this one and see if there is any others while looking
 [2010-06-18 08:43 UTC] daniel dot baulig at gmx dot de
After thinking a bit about it I came to the conclusion this might be a feature, not a bug.
If you are handed a PDOStatement from some other source (a library or a callee) you might not know which exact columns are in the result set. Because there also is no way to look them up you are stuck with "brute force" binding each column, that might be in that result set. If this would throw an Exception you would need to try { } catch ( PDOException $e ) { } every single bindColumn.
While I do think this would be the correct approach from a design standpoint it is very clunky and cumbersome actually programming. If this method only issues a warning then you could simply @ supress that warning and try bindColumn on whatever you like. However, if this behaviour remains it should be documentet clearly in the PHP PDO manual, because it is not what you'd expect.
 [2011-06-01 15:23 UTC] iliaa@php.net
Automatic comment from SVN on behalf of iliaa
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=311711
Log: Fixed bug #52104 (bindColumn creates Warning regardless of ATTR_ERRMODE settings).
 [2011-06-01 15:23 UTC] iliaa@php.net
-Status: Assigned +Status: Closed -Assigned To: kalle +Assigned To: iliaa
 [2011-06-01 15:23 UTC] iliaa@php.net
This bug has been fixed in SVN.

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.


 [2012-04-18 09:50 UTC] laruence@php.net
Automatic comment on behalf of iliaa
Revision: http://git.php.net/?p=php-src.git;a=commit;h=8083c1ab893e62e5b99b48308bb44e65c25dd03c
Log: Fixed bug #52104 (bindColumn creates Warning regardless of ATTR_ERRMODE settings).
 [2012-07-24 23:41 UTC] rasmus@php.net
Automatic comment on behalf of iliaa
Revision: http://git.php.net/?p=php-src.git;a=commit;h=8083c1ab893e62e5b99b48308bb44e65c25dd03c
Log: Fixed bug #52104 (bindColumn creates Warning regardless of ATTR_ERRMODE settings).
 [2013-11-17 09:37 UTC] laruence@php.net
Automatic comment on behalf of iliaa
Revision: http://git.php.net/?p=php-src.git;a=commit;h=8083c1ab893e62e5b99b48308bb44e65c25dd03c
Log: Fixed bug #52104 (bindColumn creates Warning regardless of ATTR_ERRMODE settings).
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 03 17:01:29 2024 UTC