我希望我的表使用 InnoDB 创建,以便执行复杂的事务以确保 ACID 模型。这就是我在运行时创建数据库的方式
$fields = array(
'trans_id' => array(
'type' => 'VARCHAR',
'constraint' => 30,
'unique' => TRUE
),
'detail' => array(
'type' => 'TEXT',
'null' => FALSE
),
'phone' => array(
'type' =>'TEXT',
'null' => FALSE
),
'debit' => array(
'type' => 'DOUBLE',
'unsigned' => TRUE
),
'credit' => array(
'type' => 'DOUBLE',
'unsigned' => TRUE
),
'balance' => array(
'type' => 'DOUBLE',
'unsigned' => FALSE
),
'timestamp' => array(
'type' => 'TIMESTAMP',
'default' => ['value' => 'CURRENT_TIMESTAMP', 'string' => false]
)
);
$attributes = array('ENGINE' => 'InnoDB');
$this->dbforge->add_field($fields);
$this->dbforge->create_table('my_table, TRUE, $attributes);
给出错误
<h1>A Database Error Occurred</h1>
<p>Error Number: 1064</p>
<p>You have an error in your SQL syntax; check the manual
that corresponds to your MySQL server version for the right
syntax to use near 'Array
) ENGINE = InnoDB DEFAULT CHARACTER SET = utf8 COLLATE =
utf8_general_ci' at line 8</p>
<p>CREATE TABLE IF NOT EXISTS `8882177363_table` (
`trans_id` VARCHAR(30) NOT NULL UNIQUE,
`detail` TEXT NOT NULL,
`phone` TEXT NOT NULL,
`debit` DOUBLE UNSIGNED NOT NULL,
`credit` DOUBLE UNSIGNED NOT NULL,
`balance` DOUBLE NOT NULL,
`timestamp` TIMESTAMP NOT NULL DEFAULT Array
) ENGINE = InnoDB DEFAULT CHARACTER SET = utf8 COLLATE =
utf8_general_ci</p>
但是,当我不使用包含“ENGINE”白色创建表的属性数组时,代码工作正常。
问题已解决
通过改变
'timestamp' => array(
'type' => 'TIMESTAMP',
'default' => ['value' => 'CURRENT_TIMESTAMP', 'string' => false])
到
'timestamp' => array(
'type' => 'TIMESTAMP')
最佳答案
我对 php
一无所知,但显然你的错误信息告诉你所有的真相。
CREATE TABLE IF NOT EXISTS `8882177363_table` (
`trans_id` VARCHAR(30) NOT NULL UNIQUE,
`detail` TEXT NOT NULL,
`phone` TEXT NOT NULL,
`debit` DOUBLE UNSIGNED NOT NULL,
`credit` DOUBLE UNSIGNED NOT NULL,
`balance` DOUBLE NOT NULL,
`timestamp` TIMESTAMP NOT NULL DEFAULT Array
) ENGINE = InnoDB DEFAULT CHARACTER SET = utf8 COLLATE = utf8_general_ci
最后一个字段 timestamp
中的单词 Array
导致错误,您必须检查您的 php
代码以将其删除。
关于php - 代码点火器中的 InnoDb 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48581170/