The code
index.php file
<?php
include_once 'includes/dbh.php';
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<?php
$sql = "SELECT * FROM data";
$result = mysqli_query($conn, $sql);
$datas = array();
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
$datas[] = $row;
}
}
//print_r($datas);
//foreach ($datas[0] as $data) {
// echo $data['text']." ";
//}
?>
</body>
</html>
includes file
<?php
$server = "localhost";
$username = "";
$password = "";
$database = "test";
$conn = mysqli_connect($server, $username,
$password, $database);
if (!$conn) {
die("Connection failed: " .
mysqli_connect_error());
}
The Warning
Warning: mysqli_connect(): (HY000/1045): Access denied for user ''@'localhost' (using password: NO) in C:\xampp\htdocs\databasetoarray\includes\dbh.php on line 8 Connection failed: Access denied for user ''@'localhost' (using password: NO)
Other info The database and php files are all correctly named.
The Goal I am trying to get an array out of a database using a tutorial I found on the internet.
The Questions Does this method even work if using correct coding? If so what can I change to make it work?