ID: 33876
User updated by: php at sagi dot org
Reported By: php at sagi dot org
-Status: Bogus
+Status: Open
Bug Type: PDO related
Operating System: Linux
PHP Version: 5CVS-2005-07-27 (dev)
New Comment:
I know how string casting works, but this is not a string.
PDO knows, for example, how to convert PHP NULL to SQL NULL and not
string('') (like string casting does). Why can't it cast bool values to
an integer instead?
This behavior is bad. PDO knows how to cast the value to real php bool
when selecting, but cannot cast it back when inserting/updating, which
means a simple attempt to re-insert a row that has just been selected,
using the same object, fails.
Previous Comments:
------------------------------------------------------------------------
[2005-07-27 15:16:02] [EMAIL PROTECTED]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php
This is expected behaviour, when cast to a string bool false is
converted to "" while bool true converted to "1".
------------------------------------------------------------------------
[2005-07-27 00:14:50] php at sagi dot org
Description:
------------
Running latest php5 snapshot (php5-200507261230), PDO connected to
pgsql 8.0 server.
I'm trying to run a query similar to this:
$res = $db->prepare('SELECT id FROM table WHERE mybool = ?');
$res->execute(array(false));
PDO throws this exception: 'SQLSTATE[22P02]: Invalid text
representation: 7 ERROR: invalid input syntax for type boolean: ""'
The query that has been executed, according to the server log, is:
"SELECT id FROM table WHERE mybool = ''"
Which is obviously not right. When trying to run the same query with
bool(true) parameter, PDO correctly quotes it as '1'.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=33876&edit=1