简体   繁体   English

在sqlite3上更新查询无法通过PHP PDO工作

[英]Update query on sqlite3 not working through PHP PDO

I am using sqlite and trying to connect to it through my PHP script. 我正在使用sqlite并尝试通过我的PHP脚本连接到它。 The select query is working but the update query is not working Please find below the code snippet 选择查询有效,但更新查询无效,请在下面的代码段中查找

$dir = 'sqlite:/var/www/html/BMKAOAData.db';
$dbh  = new PDO($dir) or die("cannot open the database");

$query = 'update KAOAData set comments = :Comments where aptNo = :aptNo';
$stmt= $dbh->prepare($query);
if(!$stmt){
    echo "\nPDO::errorInfo():\n";
    print_r($dbh->errorInfo());
}

$stmt->bindParam(':Comments',$myComments,PDO::PARAM_STR);
$stmt->bindParam(':aptNo',$myaptNo,PDO::PARAM_STR);
$stmt->execute();
$count = $stmt->rowCount();
print "Updated $count rows\n";

I searched a lot for its solution and tried various methods but couldn't resolve it. 我搜索了很多解决方案,并尝试了各种方法,但无法解决。 Note that I have the database in the same directory of the script and I have given right permission to it and all its parent directory. 请注意,我在脚本的同一目录中拥有数据库,并且已对其及其所有父目录授予正确的权限。 I am executing the same query in sqlite prompt and it is working fine. 我在sqlite提示符下执行相同的查询,并且工作正常。 Please help to resolve this. 请帮助解决此问题。

Maybe is the database autocommit set to false? 也许数据库自动提交设置为false? In that case 在这种情况下

$dbh->commit();

could solve your issue 可以解决你的问题

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

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