在MySQL UPDATE(PHP/MySQL)中使用变量 [英] Using variables in MySQL UPDATE (PHP/MySQL)
本文介绍了在MySQL UPDATE(PHP/MySQL)中使用变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用此代码,因此我可以更新数据库中的记录:
I am using this code so I can update a record in database:
$query = mysql_query("UPDATE article
SET com_count = ". $comments_count
WHERE article_id = .$art_id ");
我的问题是:如何在MySQL UPDATE语句中使用变量.
My question is: How can I use variables in a MySQL UPDATE statement.
推荐答案
$query = mysql_query("UPDATE article set com_count = $comments_count WHERE article_id = $art_id");
您正在弄乱报价和连载.
You was messing up the quotes and concats.
您可以像前面的示例一样使用内联var或像这样连接它们:
You can use inline vars like the previous example or concat them like:
$query = mysql_query("UPDATE article set com_count = " . $comments_count . " WHERE article_id = " . $art_id);
这篇关于在MySQL UPDATE(PHP/MySQL)中使用变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文