0

我遇到了一个奇怪的问题,当我在我的网站上运行它时,我的查询没有返回任何内容,但是当我在 phpMyAdmin 中运行它时它返回 1 行。

$query = $this->db->query("SELECT post_date, post_id, ref_user_id FROM forum_posts WHERE post_id = (SELECT MAX(post_id) FROM forum_posts WHERE ref_post_id = $row->ref_post_id AND NOT deleted = 1 LIMIT 1) LIMIT 1");

echo $this->db->last_query().'<br>';
echo $query->num_rows();

num_rows() gives me 0. I copy the line of code that last_query() gives me and paste it into phpMyAdmin where it returns 1 row.

Any ideas why I does not work on my web site?

Thanks!

4

1 回答 1

1

您需要转义查询中的字符串以引用 PHP 变量:

$query = $this->db->query("SELECT post_date, post_id, ref_user_id FROM forum_posts 
         WHERE post_id = (SELECT MAX(post_id) 
                         FROM forum_posts WHERE ref_post_id = " . $row->ref_post_id . " AND NOT deleted = 1 LIMIT 1) LIMIT 1");
于 2013-03-13T20:27:20.150 回答