Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用Drupal7API插入MySQL位(1)字段值?_Php_Mysql_Drupal_Drupal 7_Bit - Fatal编程技术网

Php 如何使用Drupal7API插入MySQL位(1)字段值?

Php 如何使用Drupal7API插入MySQL位(1)字段值?,php,mysql,drupal,drupal-7,bit,Php,Mysql,Drupal,Drupal 7,Bit,我有以下字段的数据库表 Table=TestForm 字段: 我使用以下方法在Drupal 7中插入数据: db_insert('TestForm') ->fields(array( 'name' => "My Form", 'status' => "b'1'" ))->execute(); 谁能告诉我如何使用Drupal 7 db_insert API为位(1)字段插入数据。位(1)类型在某种程度上等于BOOL。因此,答案是: $q = "INSERT

我有以下字段的数据库表

Table=TestForm 字段:

我使用以下方法在Drupal 7中插入数据:

db_insert('TestForm')
->fields(array(
    'name' => "My Form",
    'status' => "b'1'"
))->execute();
谁能告诉我如何使用Drupal 7 db_insert API为位(1)字段插入数据。

位(1)类型在某种程度上等于BOOL。因此,答案是:

$q = "INSERT INTO {TestForm} (name, status) VALUES ('My Form', TRUE)";
db_query($q);
我们使用普通的db\u查询(db\u插入)和TRUE/FALSE,因为否则drupal会将其预处理为int,并抛出“过长”错误

请注意,您甚至不能将此TRUE/FALSE添加到db_查询的参数中,并像:status那样传递,因为它仍将被转换


希望它能为某人节省“一点”时间…:)

如果您没有得到位(1)的答案,请切换到TINYINT。
$q = "INSERT INTO {TestForm} (name, status) VALUES ('My Form', TRUE)";
db_query($q);