非法0000-00-00 00:00:00 php使用codeigniter发送到mysql的时间戳 [英] illegal 0000-00-00 00:00:00 timestamp being sent by php to mysql using codeigniter
问题描述
这里是我的CodeIgniter模型中的Database_update_entry函数,在成功提交表单后执行。
here is a Database_update_entry function in my CodeIgniter model which gets executed upon successful form submission.
<?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);
}
?>
数据库查询执行得很好....但是设置进mysql表的时间是
0000-00-00 00:00:00 ,而<?php echo time()?>
strong> 1307018223 在浏览器中....这是一个有效的UNIX时间戳...您可以在此检查时间戳有效性。
the database query gets executed fine.... but the time that gets set into the mysql table is
0000-00-00 00:00:00 whereas the <?php echo time() ?>
statement shows 1307018223 in the browser.... which is a valid UNIX timestamp... you can check the timestamp validity here.
这里是成功后从mySQL表取得数据的表的屏幕截图update_query
here is a screenshot of the table that takes data from mySQL table after successful update_query
我做错了什么? ?如何将法律时间戳从我的PHP到mySQL?
[p.s.我已经检查我的mysql表中的时间戳字段是一个时间戳字段]
what am i doing wrong??? how can i pass a legal timestamp from my php to mySQL? [p.s. i have checked that the timestamp field in my mysql table is a timestamp field]
推荐答案
mysql timestamp
字段接受 yyyy-mm-dd H:i:s
日期格式,因此您必须将日期传递到此格式,而不是UNIX时间戳
mysql timestamp
field accept yyyy-mm-dd H:i:s
format of date so you have to pass date into this format not the UNIX timestamp
而不是
'timestamp' => time()
使用
'timestamp' => date('Y-m-d H:i:s')
如果你真的想存储 UNIX时间戳
将字段类型更改为 CHAR
If you really want to store UNIX time stamp
change the field type to CHAR
这篇关于非法0000-00-00 00:00:00 php使用codeigniter发送到mysql的时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!