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 –