我的PHP代码使用PDO从SQLite表中删除行无法正常工作
问题描述:
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
$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
答
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. I modified the database path in the code accordingly and now it works!