开发者

Call to a member function bind_param() on a non-object (unable to solve despite research) [duplicate]

开发者 https://www.devze.com 2023-03-19 19:44 出处:网络
This question already has an answer here: What to do with mysqli problems? Errors like mysqli_fetch_array(): Argument #1 must be of type mysqli_result and such
This question already has an answer here: What to do with mysqli problems? Errors like mysqli_fetch_array(): Argument #1 must be of type mysqli_result and such (1 answer) 开发者_如何学运维 Closed 2 years ago.
$stmt = $mysqli->prepare('select Un from member where Lock = ? and Activated = ?');
$stmt -> bind_param("ss", 'N', 'Y');//This line gave the error
$stmt -> execute();
$stmt->store_result();//apply to prepare statement
$numRows = $stmt->num_rows;

if ($numRows > 0)//if have result
 while ($row = $stmt->fetch())

my above code gave me a "Call to a member function bind_param() on a non-object" error. I really don't get it why i getting this error. I have correct cols name.

I am new to mysqli and would like to learn how to debug such error.

  1. what is the problem with my prepare statement or bind_param()?
  2. Please teach me how to debug such error


Call to a member function bind_param() on a non-object means that $stmt, which you're trying to call bind_param on, is not an object. Why is it not an object? Because $mysqli->prepare did not return an object. Why did it not return an object?

mysqli_prepare() returns a statement object or FALSE if an error occurred.
http://www.php.net/manual/en/mysqli.prepare.php

So that means an error must have occurred. You should turn on error_reporting, which will probably tell you, or examine $mysqli->error(), which may tell you as well.


$stmt->bind_param("ss", 'N', 'Y');//This line gave the error 

Here you need to sure about data type in database.


mysqli_prepare() returns a statement object or FALSE if an error occurred.

Source.

$mysqli->prepare() may be returning FALSE. Write a condition to deal with that situation.

0

精彩评论

暂无评论...
验证码 换一张
取 消