php - 代码点火器中的 InnoDb 错误

标签 php mysql codeigniter

我希望我的表使用 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/

相关文章:

php - 使用 OpenID 证明 Stackoverflow 成员身份

mysql - 如何在 MediaWiki 数据库中进行重音和不区分大小写的搜索?

mysql - 更改 MySQL 查询中姓氏和其余姓名的位置

php - 如何从 git merge 中排除一个特定的提交(永远)

php - 为什么 CodeIgniter 的 Curl 库比在纯 PHP 中使用 Curl 慢?

PHPUnit:如何通过被测方法模拟内部调用的函数

php - 如何保存和检索内容可编辑的数据

mysql - 为什么 MySQL 在尝试创建索引时失败并显示 ERROR 156 "Table already exists"?

php - 如何计算从一个日期到另一个日期的长天数并使用 CI 插入数据库表

javascript - 解析 JSON json_encoded 数据库结果