简体   繁体   中英

Wordpress SELECT from data base

In Wordpress data base I have table banners, I try to write SELECT to get data:

'SELECT * FROM $wpdb->banners' also try 'SELECT * FROM $wpdb->wp_banners' but no one query get me ressults, what I do wrong ?

The variable $wpdb->banners needs to be a) defined somewhere (I'm not sure how this is handled in Wordpress, so you may or may not be using the right variable) and b) interpreted by PHP.

In what you've pasted here, you seem to be using single quotes, which will stop PHP interpreting the variable - it will assume you mean a literal $ , which will lead to invalid SQL. You need to either use double quotes - "SELECT * FROM {$wpdb->banners}" - or string concatenation - 'SELECT * FROM ' . $wpdb->banners 'SELECT * FROM ' . $wpdb->banners

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