fluentpdo icon indicating copy to clipboard operation
fluentpdo copied to clipboard

Bind prepare parameters

Open roquie opened this issue 5 years ago • 2 comments

I found a bug with insert or update records. Library use PDO execute() statement which all values are treated as PDO::PARAM_STR. https://php.net/manual/en/pdostatement.execute.php

But if u use PostgreSQL database booleans must be forced with PDO::PARAM_BOOL flag in the bindParam method. Instead of got a result with an error on update/insert, like this:

PDOException: SQLSTATE[22P02]: Invalid text representation: 7 ERROR:  invalid input syntax for type boolean: ""

P.S. The library needs more tests for all supported databases.

roquie avatar Oct 30 '18 20:10 roquie

This is more of an issue with PDO than with Fluent. All Fluent does is call prepare() and execute() in succession. That's sufficient for nearly every use case.

We can only do so much to support all databases and their specific data types and quirks without writing a separate library for each database. Even PDO itself doesn't support every quirk each database has. For the future, if you want to use PDO with Postgresql, and not its own library, I suggest using integers for booleans like most other DBs.

cbornhoft avatar Nov 04 '18 18:11 cbornhoft

Any value of passed to prepare PDO query must have a type. Default execute() not suitable for all variants of use. Isn't normal for boolean or integer type set up by default string type.

Example of how it is done in Eloquent (query builder of Eloquent): https://github.com/illuminate/database/blob/master/Connection.php#L596 https://github.com/illuminate/database/blob/master/Connection.php#L573

Doctrine2: https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php#L254

Propel3: https://github.com/propelorm/Propel3/blob/master/src/Propel/Runtime/Adapter/Pdo/PdoAdapter.php#L578

Maybe and here add this improvement? Because is its default behavior for most database tools...

roquie avatar Nov 05 '18 19:11 roquie