Store bids in microtime [closed]

2019-09-26 13:05发布

问题:

How would you store bids according to the local time of the server in php codeigniter? so every time the user enters a bid , the php would use a microtime function to store it?

function create($user_bid){

    $this->db->set('bid', $user_bid);
    $this->db->set('microtime'=>microtime(TRUE)));
    $this->db->insert('products',array('microtime'=>microtime(true)));


    $query= $this->db->insert('products');


    $this->load->view('bidding');   

} }

回答1:

Assuming a MySQL database, why not simply have a TIMESTAMP column on your database: http://dev.mysql.com/doc/refman/5.6/en/timestamp-initialization.html and leave MySQL to populate it for you



回答2:

What about

 $bidTime = microtime(true);
 $sql->prepare("INSERT INTO `bids` SET `microtime` = ?, [...]")
 ->execute(array( $bidTime, [...]));


回答3:

Here is the syntax for CodeIgniter to insert

$this->db->insert('bids',array('microtime'=>microtime(true)));