PDO bindValue with \ PDO :: PARAM_BOOL causes the statement to fail silently

In one server setup, a very strange error occurs. There PHP 5.3.6 with PDO driver for MySQL, the client library version 5.1.61. Everything is compiled manually.

When I bind params to bindValue and set the third parameter as \ PDO :: PARAM_BOOL, then the statement returns false and nothing happens (data is not inserted into MySQL, even no exceptions). When I do not use the third parameter, it goes well. In fact, I can not omit the third parameter, bacues Doctrine2 DBAL sets it when converting the parameters ...

Here is the code:

<?php $pdo = new \PDO('mysql:host=***;dbname=***', '***', '***'); // hidden DB access $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); $stmt = $pdo->prepare('insert into outage (name, description, start_at, end_at, is_exception, extranet_id) values (?,?,?,?,?,?)'); $stmt->bindValue(1, 'Test name', \PDO::PARAM_STR); $stmt->bindValue(2, 'Test desc', \PDO::PARAM_STR); $stmt->bindValue(3, '2012-01-01 00:00:00', \PDO::PARAM_STR); $stmt->bindValue(4, null, \PDO::PARAM_NULL); $stmt->bindValue(5, false, \PDO::PARAM_BOOL); $stmt->bindValue(6, 2, \PDO::PARAM_INT); var_dump(array('stmt result' => ($result = $stmt->execute()), 'last insert id' => $pdo->lastInsertId(), 'stmt err code' => $stmt->errorCode(), 'pdo err code' => $pdo->errorCode())); 

Result:

 array(4) { ["stmt result"]=> bool(false) ["last insert id"]=> string(1) "0" ["stmt err code"]=> string(5) "00000" ["pdo err code"]=> string(5) "00000" } 

What could go wrong? I tried this on the other 4 servers and did not get this error. Also, if I pass '0' (as a string) to $stmt->bindValue(5, false, \PDO::PARAM_BOOL); It works well.

+7
source share
1 answer

I had the same problem on Ubuntu with PHP 5.3.10. (Interestingly, there were no problems on windows with wamp ...)

This is actually a known bug in pdo: https://bugs.php.net/bug.php?id=38546

I am using PDO :: PARAM_INT instead of PDO :: PARAM_BOOL. It works well, and you do not need to convert Boolean to string, as shown above.

+12
source

All Articles