我看过其他答案,但他们没有帮助。
$postid = $_GET['p'];
$stmt = $conn->prepare('SELECT comment_id,comment_submitter_id,comment_text,comment_lava,comment_icy,comment_date,comment_parent,post_id FROM comments WHERE post_id = ? AND comment_parent = 0');
$stmt->bind_param('s', $postid);
当我在phpmyadmin中运行相同的SQL时,它会正确地获取行(?替换为1)。我的查询字符串是?p = 1。这怎么可能失败?
$postid = $_GET['p'];
$stmt = $conn->prepare('SELECT * FROM posts WHERE post_id = ?');
$stmt->bind_param('s', $postid);
$stmt->execute();
$stmt->bind_result($post_id, $post_submitter_id, $post_title, $post_text, $post_lava, $post_icy, $post_url, $post_nsfw, $post_views, $post_date, $post_heat, $post_sub);
$stmt->fetch();
一些HTML,然后是更多PHP
$query = $conn->prepare('SELECT comment_id,comment_submitter_id,comment_text,comment_lava,comment_icy,comment_date,comment_parent,post_id FROM comments WHERE post_id = ? AND comment_parent = 0');
$query->bind_param('s', $postid);
$query->execute();
$query->bind_result($comment_id, $comment_submitter_id, $comment_text, $comment_lava, $comment_icy, $comment_date, $comment_parent, $post_id);
while($query->fetch()){
$posts[] = [
'comment_id' => $comment_id,
'comment_submitter_id' => $post_submitter_id,
'comment_text' => $comment_text,
'comment_lava' => $comment_lava,
'comment_icy' => $comment_icy,
'comment_date' => $comment_date,
'comment_parent' => $comment_parent,
'comment_post_id' => $post_id
];
}
答案 0 :(得分:1)
基于标题,我假设是你得到的错误,你准备好的语句未能创建。问题出在你甚至调用bind_param之前,它正在“准备”(或更早)。
这可能有很多原因,所以我们真的需要看到更多代码。