Quantcast
Channel: Question and Answer » wpdb
Viewing all articles
Browse latest Browse all 44

Quotes in table name

$
0
0

Since WP3.5, prepare() accepts placeholders as a security measure, instead of just appending the argument to the query. Therefore, $wpdb->prefix needs to become a second parameter, called by %s:

$count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM %s WHERE answer !=' '", $wpdb->prefix . "faq_questions" ) );  

However, doing that returns the table name in quotes:

SELECT COUNT(id) FROM 'wp_faq_questions' WHERE answer !=' '

How can I fix this?


Viewing all articles
Browse latest Browse all 44

Trending Articles