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) 中使用变量
基础教程推荐
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 如何替换eregi() 2022-01-01
