Mysqli - Fetch_Array Error Call to a Member Function Fetch_Array() on a Non-Object MySQLi

mysqli - fetch_Array error call to a member function fetch_array() on a non-object mysqli

This answer has been written very long time ago and become irrelevant.

Since then I learned the proper solution for this problem and wrote it in this answer. Please navigate there.

Fatal error: call to a member function fetch_array() on boolean

From the php documentation, MySQLi::query() will:

Returns FALSE on failure. For successful SELECT, SHOW, DESCRIBE or
EXPLAIN queries mysqli_query() will return a mysqli_result object. For
other successful queries mysqli_query() will return TRUE.

This means that the following query is failing (and hence making $backup = FALSE rather than an object which explains your error statement):

$mysqli->query($bup);

Which in turn means that the sql statement $bup is causing an error. I recommend reviewing it and your table. It seems the error is not a syntax error (since a syntax error would have caused an even earlier error message), which means that MySQL can read your statement, but the operation is failing for some reason. You'll have to review your SQL statement as well as your table and see what the flaw in the logic is.

Fatal error: Call to a member function fetch_array() on a non-object in

Your $result_project_material is probably empty or your query is failing.

Try to do step by step and find where is the error, check if the result is empty before calling fetch_array().

$connect = new mysqli($dbhost, $dbuser, $dbpass, $dbname);

if ($connect->connect_errno) {
printf("Connect failed: %s\n", $connect->connect_error());
exit();
}

$result_project_material = $connect->query($sql_project_material);

if($total_project_material = $result_project_material->num_rows > 0) {
while($result_array = $result_project_material->fetch_array()) {
$rows_project_material[] = result_array;
}
}else{
$rows_project_material = array();
echo "Empty Result";
}

XAMPP, Eclipse, PHP, MySQL: Fatal error: Call to a member function fetch_array() on null

i am not saying my code bellow is best approach but you can follow and get result i also working same scenario and get success.

<?php
$server = "127.0.0.1";
$user = "root";
$pass = "root";
$db = "bencoolen";
//open connection to mysql db
$connection = mysqli_connect($server,$user,$pass,$db) or die("Error " . mysqli_error($connection));

$userid = $_REQUEST['userid'];
$password = $_REQUEST['password'];

//fetch table rows from mysql db

$sql = "select * from profiles WHERE userid= '$userid' AND password = '$password'";
$result = mysqli_query($connection, $sql) or die("Error in Selecting " . mysqli_error($connection));

// echo json_encode(mysqli_num_rows($result));
if($result){
if (mysqli_num_rows($result) >= 1 ) {
$json=array("status"=>1,"message"=>"done");
echo json_encode($json);
}else{
$json=array("status"=>0,"message"=>"email or password not match!");
echo json_encode($json);
}
}else{
$json=array("status"=>0,"message"=>"error");
echo json_encode($json);
}
mysqli_close($connection); ?>

You can use "localhost" in place of 127.0.0.1 if you are running on same machine.

and you need to call your service like:

http://localhost/login.php?userid=test&password=12345

Hope it will help you.



Related Topics



Leave a reply



Submit