打印准备好的查询时,我看到以下字符串:
"SELECT p.ID, COALESCE(w.value,Display_name) value, p.post_title, p.post_date, p.post_content,p.post_author,user_login FROM wp_posts p INNER JOIN wp_users a ON a.ID = p.post_author LEFT JOIN wp_bp_xprofile_data w ON w.user_id = a.ID WHERE post_type = \'reply\' and post_parent = 53592568 and p.ID > 53592614 AND TIMEDIFF( \'2017-12-04 06:14:58\', post_date ) < \'00:00:15\' AND post_content is not null ORDER BY post_date ASC LIMIT 0 , 5"
当我通过SQL客户端运行它时,它似乎返回良好:
但当我试着和wpdb->get_results
或wpdb->query
我的wordpress模板中的函数。
这是我的代码:
global $wpdb;
$reply_id = $_REQUEST["id"];
$postId = $_REQUEST["post_id"];
$data = date("Y-m-d H:i:sa");
$dataStr = str_replace("am","",str_replace("pm","",$data));
$mysqli_query = "SELECT p.ID, COALESCE(w.value,Display_name) value, p.post_title, p.post_date, p.post_content,p.post_author,user_login ";
$mysqli_query .= " FROM wp_posts p ";
$mysqli_query .= " INNER JOIN wp_users a ON a.ID = p.post_author ";
$mysqli_query .= " LEFT JOIN wp_bp_xprofile_data w ON w.user_id = a.ID ";
$mysqli_query .= " WHERE post_type = \'reply\' ";
$mysqli_query .= " and post_parent = %d ";
$mysqli_query .= " and p.ID > %d ";
$mysqli_query .= " AND TIMEDIFF( \'%s\', post_date ) < \'00:00:15\' ";
$mysqli_query .= " AND post_content is not null ";
$mysqli_query .= " ORDER BY post_date ASC ";
$mysqli_query .= " LIMIT 0 , 5";
$reply_query = $wpdb->prepare($mysqli_query, $postId, $reply_id, $dataStr);
$results = $wpdb->get_results( $reply_query );
var_dump($results);
这里是什么
var_dump
为我显示:
array(0) { }
有人能帮我找出这个代码的错误吗?
非常感谢。