PHP PDO obj 在 PHP CLI 上工作,但在访问页面时不起作用
作为对我之前问题的回答,我想我可能已经发现哪个部分无法正常工作。我有一小部分 PHP 代码,它使用 PDO 对象添加到 AJAX 调用中使用的 sqlite3 数据库。
当使用 php cli 通过发出命令“php add.php”执行此代码时,一切都会按预期工作,并向表中添加条目。但是,当我通过其网址访问此 php 文件时,表中没有添加任何内容。
$base = new PDO('sqlite:todo.db');
$sql = $base->prepare("INSERT INTO Tasks (content) VALUES ('testdata');");
$sql->execute();
echo "done";
“done”将出现在命令行以及网页上。谁能向我解释这种奇怪的行为?
As a response to my previous question, I think I may have discovered which part isn't working correctly. I have a small section of PHP code which uses a PDO object to add to a sqlite3 database that is used in a AJAX call.
When this code is executed using the php cli by issuing the command: "php add.php" everything works as expected and adds and entry to the table. However when I access this php file by it's web address, nothing is added to the table.
$base = new PDO('sqlite:todo.db');
$sql = $base->prepare("INSERT INTO Tasks (content) VALUES ('testdata');");
$sql->execute();
echo "done";
"done" will appear at the command line, as well as on the webpage. Can anyone explain this strange behavior to me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对此有很多可能的解释,但我大胆猜测 Web 用户无权写入 sqlite 数据库文件。
There are many possible explanations for this, but I'll venture to guess that the web user doesn't have access to write to the sqlite database file.