在MySQLi中的select语句中获取绑定参数错误

编程入门 行业动态 更新时间:2024-10-27 18:29:21
本文介绍了在MySQLi中的select语句中获取绑定参数错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在下面添加了一个精选代码段.为什么在bind_param()上出现以下错误?

I have added a select snippet below. Why am I getting the following error on bind_param()?

未捕获的错误:在布尔值上调用成员函数bind_param()

Uncaught Error: Call to a member function bind_param() on boolean

代码:

$sessien = $_POST['xsession']; $conn = new mysqli(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME); $query = "SELECT `post` FROM `user` WHERE session=? ORDER BY `thedate` DESC "; $stmt = $conn->prepare($query); $stmt->bind_param("s", $sessien); $stmt->execute(); while ($stmt -> fetch()) { echo "$post<br>"; } $stmt->close(); $conn->close();

推荐答案

在绑定之前,Mysqli prepare可以返回false,您必须检查它是否存在错误. 看看php中的这篇文章

Mysqli prepare can returns false before bind you must check it for errors. look at this article in php

php/manual/en/mysqli.error.php

$sessien = $_POST['xsession']; $conn = new mysqli(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME); /* check connection */ if ($conn->connect_errno) { printf("Connect failed: %s\n", $conn->connect_error); exit(); } $query = "SELECT `post` FROM `user` WHERE session=? ORDER BY `thedate` DESC "; $stmt = $conn->prepare($query); if ($stmt) { $stmt->bind_param("s", $sessien); //bind Response variables $stmt->bind_result($post); $stmt->execute(); while ($stmt -> fetch()) { echo "$post<br>"; } $stmt->close(); }else{ //error var_dump($conn->error); }

更多推荐

在MySQLi中的select语句中获取绑定参数错误

本文发布于:2023-10-17 22:19:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1502239.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:绑定   语句   错误   参数   MySQLi

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!