Wordpress update mysql table(Wordpress 更新 mysql 表)
问题描述
我正在为 Wordpress 编写一个插件,它应该检查一个 mysql 条目是否已经存在.
如果它不存在,Wordpress 应该将条目插入到表中.这部分按我的预期工作.
但是,如果 mysql 表中已经有一个条目,Wordpress 应该更新该表,但这不起作用.
I am writing a plugin for Wordpress, which should check if a mysql entry already exists.
If it does not exist Wordpress should insert the entry into the table. This part works as I expected.
However, if there already is an entry in the mysql table, Wordpress should update the table, but this does not work.
我使用的代码如下:
$wpdb->query($wpdb->prepare("UPDATE $table_name SET time=$current_timestamp WHERE userid=$userid"));
我在这个查询中使用的变量是正确的,因为它们被成功地用于插入到表中,但是在更新函数的某个地方出现了问题.
The variables I use in this query are correct, because they are successfully used to insert into the table, but somewhere along the way something goes wrong with the updating function.
有人可以告诉我我在这里做错了什么吗?
解决这个问题的正确方法是什么?
Can somebody please tell me what I am doing wrong here?
What is the right way to go about this?
推荐答案
time
列的值必须用单引号
$wpdb->query($wpdb->prepare("UPDATE $table_name SET time='$current_timestamp' WHERE userid=$userid"));
这篇关于Wordpress 更新 mysql 表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Wordpress 更新 mysql 表


基础教程推荐
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- 带更新的 sqlite CTE 2022-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01