doujin8476 2015-04-28 16:07
浏览 51

$ wpdb-> get_results在服务器上不返回任何内容,但适用于本地 - Wordpress

I have created a table called ccc_campaigns in my database and I am retrieving the data with the following statement:

global $wpdb;

$campaign_list = $wpdb->get_results( 
                'SELECT * 
                 FROM ccc_campaigns 
                 ORDER BY id DESC');

This works as expected on my local and on one of my servers, the data is displayed doing:

foreach ($campaign_list as $campaign)

But in the server where this wordpress is supposed to be, the query comes back empty. I can't understand or find a reason why it is failing on that server.

Any ideas?

Thank you so much

  • 写回答

1条回答 默认 最新

  • dongyin6576 2015-04-28 16:59
    关注

    Make sure the database prefix are the same.

    EDIT: I guess you are building some kind of plugin, so just to make sure, db prefix is not causing any errors, use this function instead.

    function getCampaignResults(){
        global $wpdb;
        $table_name = $wpdb->prefix . "campaigns";
        $active_rows = $wpdb->get_results(
            "SELECT * FROM {$table_name}"
        );
    
        foreach ($active_rows as $active_row){
            echo $active_row->the_title;
        }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?