mustish1
asked on
Connection Error
Can you please tell me how to i fix that error? Thanks.
SOMETHING IS WRONG HERE: function mysqli_fetch_all($result, MYSQLI_ASSOC)
SOMETHING IS WRONG HERE: function mysqli_fetch_all($result, MYSQLI_ASSOC)
Warning: mysqli_connect(): (28000/1045): Access denied for user 'HarrisK'@'ip-107-180-46-230.ip.secureserver.net' (using password: YES) in /home/hfll4ovlkhjz/public_html/config/db_connect.php on line 3
Connection error: Access denied for user 'HarrisK'@'ip-107-180-46-230.ip.secureserver.net' (using password: YES)
Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in /home/hfll4ovlkhjz/public_html/index.php on line 6
Fatal error: Uncaught Error: Call to undefined function mysqli_fetch_all() in /home/hfll4ovlkhjz/public_html/index.php:8 Stack trace: #0 {main} thrown in /home/hfll4ovlkhjz/public_html/index.php on line 8
<?php
include('config/db_connect.php');
// write query for all pizzas
$sql = 'SELECT title, ingredients, id FROM pizzas ORDER BY created_at';
// get the result set (set of rows)
$result = mysqli_query($conn, $sql);
// fetch the resulting rows as an array
$pizzas = mysqli_fetch_all($result, MYSQLI_ASSOC);
// free the $result from memory (good practise)
mysqli_free_result($result);
// close connection
mysqli_close($conn);
?>
<!DOCTYPE html>
<html>
<?php include('templates/header.php'); ?>
<h4 class="center grey-text">Pizzas!</h4>
<div class="container">
<div class="row">
<?php foreach($pizzas as $pizza): ?>
<div class="col s6 m4">
<div class="card z-depth-0">
<img src="img/pizza.svg"class="pizza">
<div class="card-content center">
<h6><?php echo htmlspecialchars($pizza['title']); ?></h6>
<ul class="grey-text">
<?php foreach(explode(',', $pizza['ingredients']) as $ing): ?>
<li><?php echo htmlspecialchars($ing); ?></li>
<?php endforeach; ?>
</ul>
</div>
<div class="card-action right-align">
<a class="brand-text" href="details.php?id=<?php echo $pizza['id'] ?>">more info</a>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
<?php include('templates/footer.php'); ?>
</html>
The error message you're recieving is telling you that you don't have access to the DB. In your db_connect.php file, you'll need to check your connection settings - the host, the DB, the username and the password. One of those is wrong.
ASKER
every thing looks good. I got a new error
Fatal error: Call to undefined function mysqli_fetch_all() in /home/hfll4ovlkhjz/public_ html/index .php on line 8
Fatal error: Call to undefined function mysqli_fetch_all() in /home/hfll4ovlkhjz/public_
<?php
// connect to the database
$conn = mysqli_connect('localhost', 'HarrisK', 'Test1234', 'ninja_pizza');
//$conn = mysqli_connect('107.180.46.230', 'HarrisK', 'Test1234', 'ninja_pizza');
// check connection
if(!$conn){
echo 'Connection error: '. mysqli_connect_error();
}
?>
OK. In that case, your server doesn't have the Native MySQL driver installed, which means you don't have the fetch_all() method.
You have a couple of options - you can either speak to your host (or do it yourself) and get the mysqlnd driver installed, or you can build your own array using mysql_fetch in a while loop:
You have a couple of options - you can either speak to your host (or do it yourself) and get the mysqlnd driver installed, or you can build your own array using mysql_fetch in a while loop:
$pizzas = [];
while ($row = $result->fetch_assoc()) {
$pizzas[] = $row;
}
ASKER
I got an error after i replace the line.
<?php
include('config/db_connect.php');
// write query for all pizzas
$sql = 'SELECT title, ingredients, id FROM pizzas ORDER BY created_at';
// get the result set (set of rows)
$result = mysqli_query($conn, $sql);
// fetch the resulting rows as an array
//$pizzas = mysqli_fetch_all($result, MYSQLI_ASSOC);
//$pizzas = mysqli_fetch_assoc($result, MYSQLI_ASSOC);
// free the $result from memory (good practise)
$pizzas = [];
while ($row = $result->fetch_assoc()) {
$pizzas[] = $row;
mysqli_free_result($result); }
// close connection
mysqli_close($conn);
?>
<!DOCTYPE html>
<html>
<?php include('templates/header.php'); ?>
<h4 class="center grey-text">Pizzas!</h4>
<div class="container">
<div class="row">
<?php foreach($pizzas as $pizza): ?>
<div class="col s6 m4">
<div class="card z-depth-0">
<img src="img/pizza.svg"class="pizza">
<div class="card-content center">
<h6><?php echo htmlspecialchars($pizza['title']); ?></h6>
<ul class="grey-text">
<?php foreach(explode(',', $pizza['ingredients']) as $ing): ?>
<li><?php echo htmlspecialchars($ing); ?></li>
<?php endforeach; ?>
</ul>
</div>
<div class="card-action right-align">
<a class="brand-text" href="details.php?id=<?php echo $pizza['id'] ?>">more info</a>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
<?php include('templates/footer.php'); ?>
</html>
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Thank You.
No worries