zend-db
zend-db copied to clipboard
Boolean values in the Mysql Statements cause execute to silently fail
- [X] I was not able to find an open or closed issue matching what I'm seeing.
- [X] This is not a question. (Questions should be asked on slack (Signup for Slack here) or our forums.)
So I've been hitting my head on the wall for the entire day on this and I just managed to figure it out.
Although in theory zend-db is properly handling boolean values in the Statement:: bindParametersFromContainer()
it appears that there is a bug lying in PHP which is still there in 7.1 and 7.2 (https://bugs.php.net/bug.php?id=38546).
Passing PDO::PARAM_BOOL
in the bindParam
causes the PDOStatement::execute()
to silently return false
and not throw any exception, even though PDO::ATTR_ERRMODE
is set to PDO::ERRMODE_EXCEPTION
The reason I'm opening this is to bring it to your attention and perhaps discuss if booleans should be treated as integers until a fix is available
Code to reproduce the issue
$sql = new Sql($this->getDbAdapter());
$insert = $sql->insert()
->into('Table')
->values([ 'field' => true ]);
try {
$insertStatement = $sql->prepareStatementForSqlObject($insert);
$result = $insertStatement->execute();
} catch( \Exception $e ) {
// will never get here
}
// this is false
return ( $result && $result->getAffectedRows() > 0 );
Expected results
The statement should get prepared in the mysql and then get executed. However that is not the case. Looking into mysql's general_log_file one can see the statement being prepared but never executed.
Actual results
PDOStatement::execute()
returns false and no exception was thrown thus the only way to detect that the query failed is via the getAffectedRows()
but there is absolutely no indication on what went wrong.
@twmobius I tried reproducing this and couldn't. It works as expected on: zend-db 2.9.3 PHP 7.1.20 MariaDB 10.1.29
Can you state what versions this isn't working on please.
Sorry completely missed this.
It's been a while but I believe this happened on PHP 7.2.6, mySQL 5.7.22 and zend-db 2.9.3. I will remove my workaround and see if I can still reproduce it
This repository has been closed and moved to laminas/laminas-db; a new issue has been opened at https://github.com/laminas/laminas-db/issues/46.