Yii中带有PostgreSQL的布尔类型

Yii中带有PostgreSQL的布尔类型,yii,Yii,简单Postgres表: 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, )

简单Postgres表:

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,
    ));
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
一切正常:

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,
    ));
我收到错误

Yii::app()->db->createCommand()->insert('test', array(
        'id'=>1,
        'val'=>true,
    ));
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

我错了吗?

在“db”组件中,将属性设置为false/null。将其设置为true通常会触发此错误


Postgres支持准备好的语句,因此无需模拟。

在“db”组件中,将属性设置为false/null。将其设置为true通常会触发此错误


Postgres支持预处理语句,因此无需模拟。

Php将布尔值转换为整数,如果值为“false”,则转换为“”。看看重点是PDO中的类型转换,您的链接非常有用。谢谢!现在在Yii GitHub上出现了一个问题:请发布您的“db”组件设置。Php正在将布尔值转换为整数,如果值为“false”,则转换为“”。看看重点是PDO中的类型转换,您的链接非常有用。谢谢!现在在Yii-GitHub上有一个问题:请发布您的“db”组件设置。