简体   繁体   English

查询自定义WordPress / buddyPress表(PHP / MySQL)

[英]Query Custom WordPress/buddyPress Table (PHP/MySQL)

I have been looking around and trying different things for a while and no luck. 我一直在环顾四周,尝试不同的方法已经有一段时间了,但是没有运气。

Scenario: I have WordPress/BuddyPress and I added in a few new tables to the database through phpMyAdmin. 场景:我有WordPress / BuddyPress,我通过phpMyAdmin在数据库中添加了一些新表。 I cannot run a successful query to them, yet I can to all the original tables. 我无法对它们运行成功的查询,但可以查询所有原始表。 I have tried many things, this is my most recent try, still not working: 我已经尝试了很多东西,这是我最近的尝试,仍然无法正常工作:

$b1_exc = $wpdb->get_results( $wpdb->prepare("SELECT * FROM memberbadge
WHERE 1") );

I would really appreciate a solution to add custom tables and be able to query them. 我真的很感谢添加自定义表并能够查询它们的解决方案

Thank you in advance! 先感谢您!

As of 3.5, wpdb::prepare() enforces a minimum of 2 arguments. 从3.5开始,wpdb :: prepare()强制执行至少2个参数。

This is the correct syntax for wpdb::prepare(), use this. 这是wpdb :: prepare()的正确语法,请使用此语法。

$result = $wpdb->get_results( $wpdb->prepare("SELECT * FROM memberbadge WHERE %d", 1) );

It's probably a prefix problem. 这可能是前缀问题。 Try: 尝试:

$wpdb->get_results( "SELECT * FROM {$wpdb->prefix}memberbadge") );

If you really need a WHERE clause and the variable comes from user input, then use prepare . 如果您确实需要WHERE子句,并且变量来自用户输入,请使用prepare

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM