简体   繁体   中英

MySQL query works from phpMyAdmin and returns rows, but $wpdb->get_results return nothing

I am trying execute a mySQL query from $wpdb->get_results , but nothing returns while it works fine from phpAdmin and returns.

SQL code:

  $sql=" select SQL_CALC_FOUND_ROWS ref_id,
        case status
        when 0 then 'Waiting'
        when 1 then 'Invited'
        when 2 then 'Joined'
        when 3 then 'OPTOUT'
        else 'Unknow'
     end as Status,
     email,
     CONCAT(fname,' ',lname) as Name,
     ref_twitter,
     ts,
     twitter
     from ".$wpdb->base_prefix."waitingList where status!=-1 and ref_id=".$current_user->id

$invitess =$wpdb->get_results($sql);

$invitess does not return any thing.

Please help me.

Make sure $wpdb is defined. If you're doing this from within a function, make sure to declare: global $wpdb;

If that still doesn't work, try including wp-load.php .

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