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 表
基础教程推荐
- MySQL 中的类型:BigInt(20) 与 Int(20) 2021-01-01
- mysql选择动态行值作为列名,另一列作为值 2021-01-01
- 在多列上分布任意行 2021-01-01
- oracle区分大小写的原因? 2021-01-01
- 如何在 SQL 中将 Float 转换为 Varchar 2021-01-01
- 什么是 orradiag_<user>文件夹? 2022-01-01
- 表 './mysql/proc' 被标记为崩溃,应该修复 2022-01-01
- 二进制文件到 SQL 数据库 Apache Camel 2021-01-01
- 如何根据该 XML 中的值更新 SQL 中的 XML 2021-01-01
- 在 MySQL 中:如何将表名作为存储过程和/或函数参数传递? 2021-01-01
