PDO bug workaround #296

Closed
wants to merge 1 commit into
from

Projects

None yet

5 participants

@dasmfm
dasmfm commented Apr 2, 2013

In combination of PHP 5.4 and Doctrine 2 (upto 2.4Beta1) there's a bug with "boolean" type of field.
Ref link: http://stackoverflow.com/questions/10242312/pdo-bindvalue-with-pdoparam-bool-causes-statement-execute-to-fail-silently

This patch binds int instead of bool and everything goes working fine.

@dasmfm dasmfm PDO bug workaround
In combination of PHP 5.4 and Doctrine 2 (upto 2.4Beta1) there's a bug with "boolean" type of field.
Ref link: http://stackoverflow.com/questions/10242312/pdo-bindvalue-with-pdoparam-bool-causes-statement-execute-to-fail-silently

This patch binds int instead of bool and everything goes working fine.
79c36f6
@doctrinebot

Hello,

thank you for positing this Pull Request. I have automatically opened an issue on our Jira Bug Tracker for you with the details of this Pull-Request. See the Link:

http://doctrine-project.org/jira/browse/DBAL-480

@Ocramius
Member
Ocramius commented Apr 2, 2013

@dasmfm can you write a test that fails on 5.4? We have travis to check such a behavior.

@stof stof commented on the diff Apr 2, 2013
lib/Doctrine/DBAL/Driver/PDOStatement.php
@@ -47,4 +47,13 @@ public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null)
return parent::setFetchMode($fetchMode, $arg2, $arg3);
}
+
+ public function bindValue($parameter, $value, $data_type = \PDO::PARAM_STR)
@stof
stof Apr 2, 2013 Member

Please use camelCased names

@stof stof commented on the diff Apr 2, 2013
lib/Doctrine/DBAL/Driver/PDOStatement.php
@@ -47,4 +47,13 @@ public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null)
return parent::setFetchMode($fetchMode, $arg2, $arg3);
}
+
+ public function bindValue($parameter, $value, $data_type = \PDO::PARAM_STR)
+ {
+ if ($data_type == \PDO::PARAM_BOOL)
+ {
+ $data_type = \PDO::PARAM_INT;
+ }
@stof
stof Apr 2, 2013 Member

This looks wrong to me for databases where booleans are not sotred as integers (Postgres for instance)

@beberlei
Member
beberlei commented Apr 6, 2013

I am not sure we should fix PDO bugs in Doctrine since this is actually also just using the parameters wrong.

@beberlei
Member
beberlei commented May 9, 2013

The fix is actually to pass an integer to $stmt>bindValue()/$stmt->bindParam() as we do in the ORM, instead of a boolean. Even if you have PARAM_BOOL. Its weird, but thats just how the PDO API works.

Its a PDO, not a Doctrine Bug and we won't add a workaround.

@beberlei beberlei closed this May 9, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment