我有一些代码可以将记录插入到 SQLite 表中:
$statement = $db -> prepare("INSERT INTO posts (postedOn, content, tags) VALUES (DATE('now'), :content, :tags)");
$statement -> bindParam(':content', $content);
$statement -> bindParam(':tags', $tags);
问题在于 postsOn 列仅获取日期,而不获取帖子的时间。我尝试使用 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()那样准备?
最佳答案
http://www.sqlite.org/lang_datefunc.html
sqlite 中没有 NOW()
函数,请尝试在 datetime()
中使用 'now'
字符串。 SQLite 2009 Pro 必须有自己的此功能的实现,您可以尝试自己在 php 中实现:http://php.net/manual/en/pdo.sqlitecreatefunction.php
关于PHP PDO 不会使用 NOW() 准备语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10571498/