Converting mysql_query to $wpdb->get_results

前端 未结 1 496
鱼传尺愫
鱼传尺愫 2021-01-28 16:29

Afetr updating php on the server i have some problems with mysql_query. There are 2 functions in your code that have been deprecated in the current version of PHP : mysql_fetch_

相关标签:
1条回答
  • 2021-01-28 16:53

    mysql_query return a resource. So you get this error by using $wpdb->get_results.

    mysql_query() returns TRUE on success or FALSE on error. The returned result resource should be passed to mysql_fetch_array(), and other functions for dealing with result tables, to access the returned data.

    You will replace 2 function mysql_fetch_array() and mysql_query instance of $wpdb->get_results. You will define return type -- ARRAY_A, ARRAY_N , OBJECT ,OBJECT_K

    global $wpdb;
    
    $ck_sql = $wpdb->get_results("SELECT ck_ips, ck_rating_up, ck_rating_down FROM `$table_name` WHERE ck_comment_id = $comment_id", ARRAY_A);
    foreach($ck_sql as $row) {
        echo $row['ck_ips'] . ' ' . $row['ck_rating_up']. ' ' . $row['ck_rating_down '];
    }
    
    0 讨论(0)
提交回复
热议问题