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 表


- 导入具有可变标题的 Excel 文件 2021-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- SQL 临时表问题 2022-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 更改自动增量起始编号? 2021-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01