简体   繁体   中英

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. 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.

This is the correct syntax for wpdb::prepare(), use this.

$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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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