2013-02-22 56 views
-3

如何根据服务器在php codeigniter中的当地时间存储出价? 所以每次用户输入出价时,php都会使用microtime函数来存储它?以microtime存储出价

函数来创建($ 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'); 

}}

+5

[你试过什么?](http://www.whathaveyoutried.com/)参见[请咨询](http://stackoverflow.com/questions/ask-advice)。 – 2013-02-22 18:55:19

+1

你问哪一部分?如何生成microtime价值或如何存储它?无论哪种方式,显然你没有自己研究过这个问题。 – 2013-02-22 19:09:28

+0

我已经尝试了上面的代码,它插入了出价,但没有时间出价。我希望它存储出价的时间 – user2040859 2013-02-22 19:27:23

回答

0

假设一个MySQL数据库,为什么不简单地在你的数据库上有一个TIMESTAMP列:http://dev.mysql.com/doc/refman/5.6/en/timestamp-initialization.html并让MySQL为你填充它

+0

谢谢,有没有可能以毫秒为单位存储它 – user2040859 2013-02-22 20:50:56

+0

MySQL 5.6.4及更高版本扩展了对TIME,DATETIME和TIMESTAMP值的小数秒支持,最高可达微秒(6位数)精度 - http://dev.mysql.com/doc/refman/5.6/zh/fractional-seconds.html – 2013-02-22 21:43:49

0

什么

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

这里是笨的语法插入

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

如何将它链接到我存储在数据库中的出价, – user2040859 2013-02-22 19:35:57

+0

您可以使用$ this-> db-> where('id',$ id) - > update('bids',array('microtime' => microtime(true));其中$ id是您正在更新的标识 – skrilled 2013-02-22 19:55:58