本文介绍了使用PDO prepare()的PHP Sql Views计数器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个变量$id,它为我提供了当前文章的id,这可以帮助我在当前文章的数据库中进行更新查询.

I have a variable $id wich gives me the id of the current article and this can help me to make an update query in my database on current article.

这是我的代码:

 $vizualizari = $current_views+1;
    $sql1= "UPDATE detalii_cantari SET viz = viz WHERE id = {$id};";
$q1 = $dbh->prepare($sql1);
$q1->execute(array(':viz'=>$vizualizari));

我没有收到任何错误,但是我的代码仍然无法正常工作...

I don't get any errors but my code still not working...

推荐答案

您的正确代码在这里:

$vizualizari = $current_views+1;
    $sql1= "UPDATE detalii_cantari SET viz = :viz WHERE id = {$id}";
$q1 = $dbh->prepare($sql1);
$q1->execute(array(':viz'=>$vizualizari));

此处不需要sql末尾的

;,并且由于PDO,viz = viz必须成为viz = :viz.

; from the end of sql is not needed here and viz = viz must become viz = :viz because of PDO.

这篇关于使用PDO prepare()的PHP Sql Views计数器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 02:30