douza6300 2018-05-24 08:31 采纳率: 0%
浏览 304
已采纳

Wordpress - $ wpdb-> get_results没有得到任何结果

I made a small function in a custom page to get the content from a table and to display it to the user. It was working correctly before but since I changed the DNS it isn't working anymore.

Before, my code looked like this :

global $wpdb;
$table = "0_luxcom_token";
$query = $wpdb->prepare("SELECT token_name, token_dateexp FROM $table");
$resultat = $wpdb->get_results($query, ARRAY_A);

PHP was returning an error because prepare() didn't have an argument but it was still working.
Now, PHP is returning me a fatal error so it doesn't work anymore. I changed my code to this :

global $wpdb;
$table = "0_luxcom_token";
$query = $wpdb->prepare("SELECT token_name, token_dateexp FROM %s", $table);
$resultat = $wpdb->get_results($query, ARRAY_A);

I don't get any error from prepare() but now, get_results->($query, ARRAY_A); doesn't return anything.

I tried var_dump($resultat) and it returned me

array(0){ }

Then I tried var_dump($query) and it returned me

string(54) "SELECT token_name, token_dateexp FROM '0_luxcom_token'"

I noticed when I put my table in the argument it's now between simple quote, so I wonder if it's because of this it's not working anymore but I'm not sure.

  • 写回答

1条回答 默认 最新

  • donglao6169 2018-05-24 08:36
    关注

    If you have no variables to prepare for query, use simple query method:

    global $wpdb;
    $table = "0_luxcom_token";
    $query = $wpdb->query("SELECT token_name, token_dateexp FROM $table");
    $resultat = $wpdb->get_results($query, ARRAY_A);
    

    Or just get_results:

    global $wpdb;
    $table = "0_luxcom_token";
    $resultat = $wpdb->get_results("SELECT token_name, token_dateexp FROM $table", ARRAY_A);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥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 支付宝网页转账系统不识别账号