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.
您可以像前面的示例一样使用内联变量,也可以像这样连接它们:
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) 中使用变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 MySQL UPDATE (PHP/MySQL) 中使用变量
- PHP Count 布尔数组中真值的数量 2021-01-01
- 正确分离 PHP 中的逻辑/样式 2021-01-01
- 如何定位 php.ini 文件 (xampp) 2022-01-01
- Laravel 仓库 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01
- Mod使用GET变量将子域重写为PHP 2021-01-01
- 没有作曲家的 PSR4 自动加载 2022-01-01
- 带有通配符的 Laravel 验证器 2021-01-01
- 从 PHP 中的输入表单获取日期 2022-01-01