非法的00:00:00使用codeigniter通过php发送到mysql的时间戳

Rak*_*kib 6 php mysql timestamp codeigniter

这是我的CodeIgniter模型中的Database_update_entry函数,它在成功提交表单后执行.

<?php
    function update_entry(){
        $data = array(
            'sl' => $this->input->post('item_sl'),
            'item_name' => $this->input->post('item_name'),
            'img_url' => $this->input->post('img_url'),
            'sound_url' => $this->input->post('sound_url'),
            'price' => $this->input->post('price'),
            'unit' => $this->input->post('unit'),
            'timestamp' => time(),
        );
        echo "current time: ".  time();
        $this->db->update(MY_TABLE_NAME, $data);
    }
?>
Run Code Online (Sandbox Code Playgroud)

数据库查询执行得很好....但是设置到mysql表中的时间是 00:00:00,<?php echo time() ?>语句在浏览器中显示1307018223 ....这是一个有效的UNIX时间戳. ..你可以在这里检查时间戳的有效性.

这是在成功更新update_query之后从mySQL表中获取数据的表的屏幕截图http://s3.amazonaws.com/awesome_screenshot/658523?AWSAccessKeyId=0R7FMW7AXRVCYMAPTPR2&Expires=1307020816&Signature=AncPjnzG9p9QT7zebZp7c9teB0%3D

我究竟做错了什么???我怎样才能将法律时间戳从我的php传递给mySQL? [ps我已经检查过mysql表中的时间戳字段是时间戳字段]

Sha*_*ngh 5

mysql timestamp字段接受yyyy-mm-dd H:i:s日期格式,因此您必须将日期传递给此格式而不是UNIX时间戳

而不是这个

'timestamp' => time()
Run Code Online (Sandbox Code Playgroud)

使用

'timestamp' => date('Y-m-d H:i:s')
Run Code Online (Sandbox Code Playgroud)

如果你真的想存储UNIX time stamp更改字段类型CHAR