Connection Error

mustish1
mustish1 used Ask the Experts™
on
Can you please tell me how to i fix that error?  Thanks.

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

Open in new window


<?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>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2018
Distinguished Expert 2018

Commented:
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.

Author

Commented:
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

<?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();
	}
?>

Open in new window

Most Valuable Expert 2018
Distinguished Expert 2018

Commented:
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:

$pizzas = [];
while ($row = $result->fetch_assoc()) {
    $pizzas[] = $row;
}

Open in new window

C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Author

Commented:
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>

Open in new window


screenshot.JPG
Most Valuable Expert 2018
Distinguished Expert 2018
Commented:
Sure. You need this:

<?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);

// create an array from the query result
$pizzas = [];
while ($row = mysqli_fetch_assoc($result)) {
    $pizzas[] = $row;
}

// free the $result from memory (good practise)
mysqli_free_result($result);
// close connection
mysqli_close($conn);
?>

Open in new window

Author

Commented:
Thank You.
Most Valuable Expert 2018
Distinguished Expert 2018

Commented:
No worries

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial