简体   繁体   中英

DOCTRINE PDO postgresql bindValue() with null -> SQLSTATE[22P02]

I am banging my head on the wall with PDO PostgreSQL and PHP (+ some DOCTRINE and SYMFONY - but I don't use ORM)

At some point I have a null value that I want to use in the bindParam() function.

It goes like:

$sqlReadyToBindValue->bindValue(':an_integer_field',null,PDO::PARAM_INT);

And I ve tried also with:

$sqlReadyToBindValue->bindValue(':an_integer_field',null,PDO::PARAM_NULL);

In both cases it raises an exception:

SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for integer: """ at [SYMFONY FOLDER]\\vendor\\doctrine\\dbal\\lib\\Doctrine\\DBAL\\Driver\\AbstractPostgreSQLDriver.php line 91

I don't get it because any other thing I do with the bindValue() function goes thru.

I notice reading the log that my null value becomes two simple quotes when going thru DOCTRINE , something like:

at DBALException ::driverExceptionDuringQuery (object(Driver), object(PDOException), 'SELECT an_integer_field FROM a_table WHERE an_integer_field = :an_integer_field', array(':an_integer_field' => '')) in vendor\\doctrine\\dbal\\lib\\Doctrine\\DBAL\\Statement.php at line 17

and then: at AbstractPostgreSQLDriver ->convertException ('An exception occurred while executing ' SELECT an_integer_field FROM a_table WHERE an_integer_field = :an_integer_field ' with params [""]: SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for integer: ""', object(PDOException)) in vendor\\doctrine\\dbal\\lib\\Doctrine\\DBAL\\DBALException.php at line 116

Then it raises the first Exception, I've wrote on earlier: AbstractPostgreSQLDriver.php line 91 (the one that splashes on the screen)

Any clue? Is there maybe a way to make sure null doesn't become quotes in DOCTRINE ?

我通过在SQL查询中使用“ IS null”检查而不是将参数绑定到它来进行了变通。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM