普通SQLi语句到Prepared Statement Troubleshoot

时间:2018-10-18 00:04:05

标签: php mysqli prepared-statement

我一直在尝试(无尽地)转换以下普通SQLi语句,经过数小时的尝试,我仍然看不到我要去哪里。该语句如下:

$get_comments = mysqli_query($con, "SELECT * FROM blog_post_comments WHERE post_id='$post_id' AND removed='no' ORDER BY id ASC");
$count = mysqli_num_rows($get_comments);

if ($count != 0) {

    while($comment = mysqli_fetch_array($get_comments)) {

        $comment_body = $comment['post_body'];
        $posted_to = $comment['posted_to'];
        $posted_by = $comment['posted_by'];
        $date_added = $comment['date_added'];
        $removed = $comment['removed'];
        $blog_comment_id = $comment['id']; 


        etc... }

这是我准备好的声明的最新版本:

$no = 'no';  

$get_comments = mysqli_prepare($con, "SELECT * FROM blog_post_comments WHERE post_id=? AND removed=? ORDER BY id ASC");
$get_comments->bind_param('is', $post_id, $no);
$get_comments->execute();

$result = $get_comments->get_result();
$count = $result->num_rows;

$get_comments->free_result();

if ($count != 0) {

    while($comment = $result->fetch_assoc()) {

        $comment_body = $comment['post_body'];
        $posted_to = $comment['posted_to'];
        $posted_by = $comment['posted_by'];
        $date_added = $comment['date_added'];
        $removed = $comment['removed'];
        $blog_comment_id = $comment['id']; 

        etc... }

有人可以看看我是否在这里遗漏了什么吗?在第二条语句中,我没有收到错误,但是我也没有加载任何要显示的帖子。

0 个答案:

没有答案
相关问题