2012-05-13 106 views
2

我有一些代碼,將記錄插入一個SQLite表:PHP PDO不會準備語句NOW()

$statement = $db -> prepare("INSERT INTO posts (postedOn, content, tags) VALUES (DATE('now'), :content, :tags)"); 
$statement -> bindParam(':content', $content); 
$statement -> bindParam(':tags', $tags); 

的問題是,postedOn列只獲得日期,而不是時間的帖子。我試着用NOW()代替:

$statement = $db -> prepare("INSERT INTO posts (postedOn, content, tags) VALUES (NOW(), :content, :tags)"); 

,但我得到

Call to a member function bindParam() on a non-object 

第一bindParam電話。這工作正常,如果我在SQLite 2009 Pro中運行它:

INSERT INTO posts (postedOn, content, tags) VALUES (NOW(), 'some content', 'tags') 

爲什麼不準備像NOW()?

回答

1

問題是NOW()函數在SQLite中不存在。請使用datetime('NOW','localtime')。這是NOW function in SQLite的替代例子