当其中需要是动态的时,在数据库中增加整型字段 时间:2021-05-10 作者:user44109 我有一个数据库列,名为;向上投票;。我有另一个专栏,叫做;用户ID;。我想增加“中的值”;“更新”;用户ID与我提供的动态变量匹配的列。以下是我的尝试: $results = $wpdb->query("UPDATE points SET upvotes = upvotes + 1 WHERE userid= %d", $theDynamicUserID); 这会产生以下错误:[You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '%d' at line 1]<br /><code>UPDATE points SET upvotes = upvotes + 1 WHERE userid= %d</code> 编辑:这些堆栈交换帖子似乎暗示这是可能的,但我无法正确理解语法:https://stackoverflow.com/questions/973380/sql-how-to-increase-or-decrease-one-for-a-int-column-in-one-commandhttps://stackoverflow.com/questions/2259155/increment-value-in-mysql-update-query 2 个回复 最合适的回答,由SO网友:Buttered_Toast 整理而成 刚刚注意到您缺少一个准备。您的代码应该如下所示$results = $wpdb->query($wpdb->prepare(\'UPDATE points SET upvotes = upvotes + 1 WHERE userid= %d\', $theDynamicUserID)); SO网友:user44109 编辑:这似乎是个坏主意:我似乎已经解决了这个问题,首先构建了如下查询:$theQuery = "UPDATE points SET upvotes = upvotes + 1 WHERE userid = \'".$theDynamicUserID."\'"; $results = $wpdb->query($theQuery); 文章导航