2016-05-13 52 views
0

我敲在牆上我的頭PDO的PostgreSQLPHP(+一些教義Symfony的 - 但我不使用ORM)教義PDO的PostgreSQL bindValue()與空 - > SQLSTATE [22P02]

在某些時候,我有一個null值,我想在bindParam()函數中使用。

它是這樣:

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

而且我以前也試過:

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

在這兩種情況下,它拋出一個異常:

SQLSTATE [22P02]:無效的文本表示:7錯誤:在[SYMFONY FOLDER] \ vendor \ doctrine \ dbal \ lib \ Doctrine \ DBAL \ Driver \ AbstractPostgreSQLDriver.php行中整數:「」「的輸入語法無效91行

我不明白,因爲我用bindValue()函數做的任何其他事情都會通過。

會通教義當我發現讀我的變成兩個簡單的報價日誌,是這樣的:

在DBALException :: driverExceptionDuringQuery(對象(驅動器),對象(PDOException) ,'SELECT an_integer_field FROM a_table WHERE an_integer_field = :an_integer_field', array(':an_integer_field' => '')) 在供應商\教義\ DBAL \ lib中\學說\ DBAL \ Statement.php在管線17

然後: 在AbstractPostgreSQLDriver - > convertException('在執行時發生異常'SELECT an_integer_field FROM a_table WHERE an_integer_field = :an_integer_field'with params [「」]:SQLSTATE [22P02]:無效的文本表示形式:7錯誤:無效輸入語法爲整數:「」',對象(PDOException)) in vendor \ doctrine \ dbal \ lib \ Doctrine \ DBAL \ DBALException.php在行116

然後它提出的第一個例外,我已經寫了前面:AbstractPostgreSQLDriver.php線91(在屏幕上濺起一)

任何線索? 有沒有辦法確保DOCTRINE中的null不成爲引號?

+1

空值不是整數,所以我不認爲這可以工作。 sql使用IS NULL運算符來檢查空值。 – Cerad

+0

@Cerad,是的它確實有道理:)另外,由於該字段是一個整數,所以接受null值,它讓我認爲綁定null可以在WHERE語句中工作。我發現了一個工作,我將作爲一個補丁發佈。 – nyluje

回答

0

我通過在SQL查詢中使用'IS NULL'檢查而不是將參數綁定到它來解決問題。