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

 ID:               52104
 User updated by:  daniel dot baulig at gmx dot de
 Reported by:      daniel dot baulig at gmx dot de
 Summary:          bindColumn creates Warning regardless of ATTR_ERRMODE
                   settings
 Status:           Assigned
 Type:             Bug
 Package:          PDO related
 Operating System: Windows 7 / Debian
 PHP Version:      5.3.2
 Assigned To:      kalle

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[2010-06-18 04:50:55] ka...@php.net

Ill have a look at this one and see if there is any others while looking

------------------------------------------------------------------------
[2010-06-16 23:12:59] daniel dot baulig at gmx dot de

This code ofcourse resides in /ext/pdo/pdo_stmt.c

------------------------------------------------------------------------
[2010-06-16 23:07:37] 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 22:47:15] 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 />




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



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

Reply via email to