Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/65.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 如何使用codeigniter 3中的dbforge类设置时间戳字段中的更新属性_Php_Mysql_Sql_Codeigniter_Codeigniter 3 - Fatal编程技术网

Php 如何使用codeigniter 3中的dbforge类设置时间戳字段中的更新属性

Php 如何使用codeigniter 3中的dbforge类设置时间戳字段中的更新属性,php,mysql,sql,codeigniter,codeigniter-3,Php,Mysql,Sql,Codeigniter,Codeigniter 3,我想设置更新属性以获取应用程序的更新时间。这是我的型号代码: public function createDatabase() { $testdatabase = "testdatabase"; $this->dbforge->create_database($testdatabase); $this->db->db_select($testdatabase); $fields = array( 'id' => arr

我想设置更新属性以获取应用程序的更新时间。这是我的型号代码:

public function createDatabase() {
    $testdatabase = "testdatabase";
    $this->dbforge->create_database($testdatabase);
    $this->db->db_select($testdatabase);
    $fields = array(
        'id' => array(
            'type' => 'INT',
            'constraint' => 1,
            'unsigned' => TRUE,
        ),
        'name' => array(
            'type' => 'VARCHAR',
            'constraint' => '100',
        ),
        'establishment_date' => array(
            'type' => 'VARCHAR',
            'constraint' => '50',
            'null' => TRUE,
        ),
        'package' => array(
            'type' => 'VARCHAR',
            'constraint' => '15',
        ),
        'db_name' => array(
            'type' => 'VARCHAR',
            'constraint' => '25',
        ),
        'update_date' => array(
            'type' => 'datetime',
            'on update' => 'NOW()',
        ),
        'upgrade' => array(
            'type' => 'tinyint',
            'constraint' => '1',
            'default' => '0',
        ),
        'status' => array(
            'type' => 'tinyint',
            'constraint' => '1',
            'default' => '4',
        ),
    );
    $this->dbforge->add_field($fields);
    $this->dbforge->add_field("subscription_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP");
    $this->dbforge->add_field("subscription_expire TIMESTAMP DEFAULT '0000-00-00 00:00:00'");
    $this->dbforge->add_key('id', TRUE);
    $this->dbforge->create_table('tms_profile');
}

已成功创建表,但名为update\u date的字段上不存在更新属性。我想在字段上设置更新属性。

您所要做的就是更改
更新日期
列的
类型

....
'update_date' => array(
       'type' => 'TIMESTAMP'
 ),
.....

现在它将使用
Now()
使用内联声明进行更新,如下所示:

`update_stamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP',

+1到
$this->dbforge->add_字段(“订阅日期时间戳默认当前时间戳”)
作为
'default'=>'CURRENT\u TIMESTAMP'
的替代,如果它是上面
$fields
的一部分,则不起作用