Illegally 0000-00-00 00:00:00 timestamp sent to php in mysql using codeigniter

here is the Database_update_entry function in my CodeIgniter model, which runs when the form is submitted successfully.

<?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); } ?> 

the database query runs fine ... but the time that is set to the mysql table is 0000-00-00 00:00:00 , while the <?php echo time() ?> statement shows 1307018223 in the browser .... which is valid UNIX mark ... you can check the expiration of the label .

here is a screenshot of the table that takes the data from the mySQL table after successful update_query http://s3.amazonaws.com/awesome_screenshot/658523?AWSAccessKeyId=0R7FMW7AXRVCYMAPTPR2&Expires=1307020816&Signature=AncPjnzG9p9QTX7ze

what am I doing wrong??? how can i pass legal timestamp from my php to mySQL? [Postscript I checked that the timestamp field in my mysql table is a timestamp field]

+6
source share
4 answers

The mysql timestamp field accepts the yyyy-mm-dd H:i:s date format, so you need to pass the date to this format, not the UNIX timestamp

instead of this

 'timestamp' => time() 

Using

 'timestamp' => date('Ymd H:i:s') 

If you really want to keep the UNIX time stamp , change the field type to CHAR

+5
source

Use date('Ymd H:i:s', time());

;)

+3
source

You need to specify a time stamp line, not an integer. Try:

 'timestamp' => date('Ymd H:i:s', time()), 
+3
source

formatting time: date('Ymd H:i:s', time())

+2
source

Source: https://habr.com/ru/post/889623/


All Articles