#49255 [Bgs]: PDO fails to insert boolean FALSE to MySQL in prepared statement

2009-08-21 Thread carysmith at creighton dot edu
 ID:   49255
 User updated by:  carysmith at creighton dot edu
 Reported By:  carysmith at creighton dot edu
 Status:   Bogus
 Bug Type: PDO related
 Operating System: Windows 2003 Ent.
 PHP Version:  5.2.10
 New Comment:

It makes no sense to change the string representation of false to 0,
because that would give problems on other places in PHP. It makes no
sense to parse the query to determine the type, as this is very hard
to
do.

This is not at all a request to make the string representation of false
to 0. I definitely understand not wanting to change the way things are
parsed into the system but the concept of requiring a 'work-around' to
pass an extremely simple type to a database seems a shame especially
considering a true value works as expected, but these are the cards we
are dealt. Loose typing can be a great boon, but also a curse.


Thank you for responding.


Previous Comments:


[2009-08-21 11:54:59] sjo...@php.net

Marking as bogus, because prepared statements are supposed to work like
this. Feel free to contact me if you disagree.



[2009-08-21 11:52:25] sjoerd-php at linuxonly dot nl

Thank you for your report.

When PDO replaces question marks in execute(), it does not take the
type of the columns into account. It thus does not know that the
parameter to execute() should be interpreted as a boolean, it simply
replaces question marks by strings. Because the string representation of
false is the empty string, it replaces the question mark by ''.

It makes no sense to change the string representation of false to 0,
because that would give problems on other places in PHP. It makes no
sense to parse the query to determine the type, as this is very hard to
do.

To work around this problem, you should convert the boolean value
yourself. You can do so like this:
$numeric_boolean = (int)$php_boolean;



[2009-08-14 15:53:18] carysmith at creighton dot edu

Description:

Before I report the bug, would just like to say that PDO is excellent
and I am enjoying working with it.

The Issue:
When attempting to insert a Boolean FALSE into a MySQL Boolean column,
the insert fails. Inserting a 0 does not. 

The following example code is borrowed from another post which was
similar http://bugs.php.net/bug.php?id=38386 and modified to accommodate
how I am using it.

Reproduce code:
---
?php
$dbh = new PDO( 'mysql:host=localhost; dbname=Testing', 'DevUser',
'p...@ssw0rd!');

// Create table
$query = 'CREATE TABLE Testing.test_boolean(TheBoolean BOOLEAN);';
$createStatement = $dbh-prepare( $query);
$createStatement-execute();

// Attempt to insert Boolean records into table - (FALSE insert fails
without error)
$query = 'insert into Testing.test_boolean set TheBoolean = ?;';
$statement = $dbh-prepare( $query);
$statement-execute(array(true));
$statement-execute(array(false));

// However by replacing Boolean with integers does work
$statement-execute(array(1));
$statement-execute(array(0));
?

Expected result:

4 rows added to the table:

1
0
1
0



Actual result:
--
3 rows added to the table:

1
1
0

Investigation of the MySQL logs shows the Boolean FALSE is inserted as
an empty string '' which fails. Please verify if I am missing something
or this cannot be reproduced. In the meantime I am changing the code to
use numbers instead of Boolean.





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



#49255 [NEW]: PDO fails to insert boolean FALSE to MySQL in prepared statement

2009-08-14 Thread carysmith at creighton dot edu
From: carysmith at creighton dot edu
Operating system: Windows 2003 Ent.
PHP version:  5.2.10
PHP Bug Type: PDO related
Bug description:  PDO fails to insert boolean FALSE to MySQL in prepared 
statement

Description:

Before I report the bug, would just like to say that PDO is excellent and
I am enjoying working with it.

The Issue:
When attempting to insert a Boolean FALSE into a MySQL Boolean column, the
insert fails. Inserting a 0 does not. 

The following example code is borrowed from another post which was similar
http://bugs.php.net/bug.php?id=38386 and modified to accommodate how I am
using it.

Reproduce code:
---
?php
$dbh = new PDO( 'mysql:host=localhost; dbname=Testing', 'DevUser',
'p...@ssw0rd!');

// Create table
$query = 'CREATE TABLE Testing.test_boolean(TheBoolean BOOLEAN);';
$createStatement = $dbh-prepare( $query);
$createStatement-execute();

// Attempt to insert Boolean records into table - (FALSE insert fails
without error)
$query = 'insert into Testing.test_boolean set TheBoolean = ?;';
$statement = $dbh-prepare( $query);
$statement-execute(array(true));
$statement-execute(array(false));

// However by replacing Boolean with integers does work
$statement-execute(array(1));
$statement-execute(array(0));
?

Expected result:

4 rows added to the table:

1
0
1
0



Actual result:
--
3 rows added to the table:

1
1
0

Investigation of the MySQL logs shows the Boolean FALSE is inserted as an
empty string '' which fails. Please verify if I am missing something or
this cannot be reproduced. In the meantime I am changing the code to use
numbers instead of Boolean.

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