Answer the question
In order to leave comments, you need to log in
How to get data from mysql?
There is a task to deduce from a database of users with a certain name. I am getting the error Couldn't fetch mysqli in. Tell me what I did wrong?
$name = "SELECT * FROM users WHERE name == 'alex'";
$result3 = mysqli_query($conn, $name);
$b = array();
if(mysqli_num_rows($result3) > 0) {
while($row = mysqli_fetch_assoc($result2)) {
$b[] = $row;
}
} else {
echo "0 results";
}
print_r($b);
Answer the question
In order to leave comments, you need to log in
The Couldn't fetch mysqli error means that you have already closed the connection to the database for some reason
Well, to answer the question from the title and rewrite all this cave horror to normal PHP
$b = $conn->query("SELECT * FROM users WHERE name = 'alex'")->fetch_all(MYSQLI_ASSOC);
if($b) {
print_r($b);
} else {
echo "0 results";
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question