1
簡單的Postgres表:布爾類型PostgreSQL的
CREATE TABLE public.test (
id INTEGER NOT NULL,
val BOOLEAN NOT NULL,
CONSTRAINT test_pkey PRIMARY KEY(id)
);
做到這一點:
Yii::app()->db->createCommand()->insert('test', array(
'id'=>1,
'val'=>true,
));
Everithing還好吧:
Executing SQL: INSERT INTO "test" ("id", "val") VALUES (:id, :val). Bound with :id=1, :val=true
但這樣
Yii::app()->db->createCommand()->insert('test', array(
'id'=>1,
'val'=>false,
));
我得到錯誤:
SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for type boolean: ""
LINE 1: INSERT INTO "test" ("id", "val") VALUES ('1', '')
^. The SQL statement executed was: INSERT INTO "test" ("id", "val") VALUES (:id, :val). Bound with :id=1, :val=false
難道我錯了嗎?
Php正在將布爾值轉換爲整數,在'false'值的情況下,轉換爲「」。看看https://bugs.php.net/bug.php?id=33876#1122477362 – sucotronic
強調在PDO中投射類型,並且你的鏈接非常有用。非常感謝! –
現在在Yii GitHub上有一個問題: http://github.com/yiisoft/yii/issues/779 –