在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);