WPDB Table Does Not Exist

时间:2015-02-27 作者:Jeremiah Prummer

根据此代码:

global $wpdb;
$sidebar_table = $wpdb->prefix . \'w3care_sidebar_position\'; 
$checkad = $wpdb->get_results( $wpdb->prepare( "SELECT ad_id, sidebar_position, ad_type FROM `%s` WHERE page_id = \'11646\' AND page_type=\'page\'",$sidebar_table ));
我收到以下错误:

WordPress database error Table \'wp_rainnews.\'wp_w3care_sidebar_position\'\' doesn\'t exist for query SELECT ad_id, sidebar_position, ad_type FROM `\'wp_w3care_sidebar_position\'` WHERE page_id = \'11646\' AND page_type=\'page\' /* From [siteurl/] in [/urltopluginindex/index.php:855] */ made by .....
但我不知道这怎么可能。如果我回显$sidebar\\u表,它将返回wp_w3care_sidebar_position, 那么这条wp\\U rainnews是从哪里来的呢?它周围的引号是什么?如果有人能提供任何帮助,我将不胜感激。:)

1 个回复
最合适的回答,由SO网友:TheDeadMedic 整理而成

您不能使用wpdb::prepare 要插入表名,只需使用"SELECT ... $sidebar_table"

结束

相关推荐

Using WPDB->Insert()

您好,我一直在用PHP开发,现在才开始向Wordpress过渡。在PHP中,我有这个-> // Prepare statement $sqlstatement = $conn->prepare(\"INSERT INTO importtest (id, area, country, city, town, postcode, lotarea, price, bedrooms, bathrooms, summary, latitude, longlitu