[英]WordPress database error with using wpdb->query
I have a query that is using $wpdb->query but every time I run it, it doesn't seem to work and is providing me with the following error message: 我有一个使用$ wpdb-> query的查询,但是每次运行它时,它似乎都无法正常工作,并向我提供以下错误消息:
WordPress database error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''4'' at line 1 for query SELECT * FROM wp_mytable OFFSET '4'
This is the code that is causing the error: 这是导致错误的代码:
$query = $wpdb->prepare("SELECT * FROM " . $wpdb->prefix . MY_TABLE . " OFFSET %s", $offset);
$fetch = $wpdb->get_results($query, 'ARRAY_A');
What am I doing wrong here? 我在这里做错了什么? I've looked at some other questions but nothing seems to be similar to my issue so I don't know what I'm missing.
我看过其他一些问题,但似乎没有什么比我的问题更相似,所以我不知道自己缺少什么。
Offset should be integer not a string. 偏移量应为整数而不是字符串。 Also offset comes along with limit
抵消也伴随极限
Replace 更换
$query = $wpdb->prepare("SELECT * FROM " . $wpdb->prefix . MY_TABLE . " OFFSET %s", $offset);
with 同
$query = $wpdb->prepare("SELECT * FROM " . $wpdb->prefix . MY_TABLE . " LIMIT %d OFFSET %d", $limit,$offset);
Not tested. 未经测试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.