简体   繁体   English

我的PHP代码无法使用PDO从SQLite表中删除行

[英]My PHP code to delete a row from an SQLite table using PDO not working

The following block of code is not working to do what it is meant to do. 下面的代码块无法正常工作。

I have confirmed that the DELETE statement (in the second line) works directly on the command line for sqlite3 where OutputID = 1 我已经确认DELETE语句(在第二行)直接在sqlite3的命令行上工作,其中OutputID = 1

$myPDO = new PDO("sqlite:$dbpath");
$stmt = $myPDO->prepare("DELETE FROM Output WHERE ID = :OutputID");
$stmt->bindParam(':OutputID', $OutputID, PDO::PARAM_INT);
$stmt->execute();
echo $stmt->rowCount();

Expected result is 1 but I get 0 预期结果是1但我得到0

The error (gotten by capturing $myPDO->errorInfo(); which returns an array) was that the database was read-only, so I moved the database file into a directory with 777 permissions (I am working in Linux environment, by the way) and changed the permissions of the database file to 777 also. 错误(捕获$ myPDO-> errorInfo()会返回数组),该错误是数据库是只读的,因此我将数据库文件移到具有777权限的目录中(我在Linux环境中工作,方式),并将数据库文件的权限也更改为777。 I modified the database path in the code accordingly and now it works! 我在代码中相应地修改了数据库路径,现在可以使用了!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM