在 MySQL UPDATE (PHP/MySQL) 中使用变量 [英] Using variables in MySQL UPDATE (PHP/MySQL)

查看:36
本文介绍了在 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.

您可以像前面的示例一样使用内联变量,也可以像这样连接它们:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆