2013-02-22 37 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