Warning: MySQLi_Query(): Couldn't Fetch MySQLi

Warning: mysqli_query(): Couldn't fetch mysqli

You forget to close your while loop. check comment in line where you need to close it.

<?php
$categories0 = mysqli_query($conn, "SELECT * FROM categories WHERE type = 'category'");
?>
<!DOCTYPE html>

<?php
while ($categories = mysqli_fetch_array($categories0, MYSQLI_ASSOC)) {// need to close your loop

$catecory_name = $categories['category'];
echo '
<div class="content">
<div class="content_container header">
<p>'.$categories['category'].'</p>
</div>
';
}// close here
$subcategories0 = mysqli_query($conn, "SELECT * FROM categories WHERE type = 'subcategory'");
// The above line is where the error occurs

while ($subcategories = mysqli_fetch_array($subcategories0, MYSQLI_ASSOC)) {
echo $subcategories['category'];

}

?>

UPDATED

Remove close connection from top because after it your query will not execute. Your connection variable is vanished after your connection is closed.

<?php
session_start();

include_once "/mysqli_connect.php";

$categories0 = mysqli_query($conn, "SELECT * FROM categories WHERE type = 'category'");

?>

mysqli_query(): Couldn't fetch mysqli error

I suspect you're calling the function multiple times. But it calls mysqli_close($conn) at the end, so when you try to use it the next time you get an error, because $conn can't be used any more.

Get rid of that line, and close the connection when the script is all done using MySQL (or don't bother, it will be closed automatically when the script ends).

Warning: mysqli_close(): Couldn't fetch mysqli

It's difficult to tell with the indentation, but in some cases you will close the connection twice...

$conn->close();

}

mysqli_close($conn);

These will both close the connection, so the second one will fail.
Probably easier to remove the $conn->close(); as it will always fall through to the second close.

Warning: mysqli_query(): Couldn't fetch mysqli in file on line number

Barmar is correct that $this->dbc is not a valid mysqli object. You are using the require_once with the file like a function. Make the config.php a class, and make the db connection from there. See here for an example of what I'm referring to. https://gist.github.com/jonashansen229/4534794

Why Warning: mysqli_query(): Couldn't fetch mysqli?

The problem is that the connection is closed when you call getData() after you have created the Display object.

The getData() call in your constructor doesn't make any sense, because you don't use/save the return value. So when then constructor is executed you open a connection, send a select query (which return value you don't save) and then close the connection. After that a getData() call results in your error message.

You can either save the result of your getData() call from the constructor in a private field and access it later or remove the getData() and $this->close(); call from the constructor and call them from outside.

mysqli::query(): Couldn't fetch mysqli

Probably somewhere you have DBconnection->close(); and then some queries try to execute .


Hint: It's sometimes mistake to insert ...->close(); in __destruct() (because __destruct is event, after which there will be a need for execution of queries)



Related Topics



Leave a reply



Submit