Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Boolean values in the Mysql Statements cause execute to silently fail #323

Open
2 tasks done
twmobius opened this issue Jun 19, 2018 · 3 comments
Open
2 tasks done

Comments

@twmobius
Copy link

twmobius commented Jun 19, 2018

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.

@shaunfreeman
Copy link

@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.

@twmobius
Copy link
Author

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

@michalbundyra
Copy link
Member

This repository has been closed and moved to laminas/laminas-db; a new issue has been opened at laminas/laminas-db#46.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants