I'm trying to retrieve all the rows from my MySQL database through a PHP script. I'm pretty sure connecting to the database went well, but the code that needs to be run afterwards doesn't get executed (or so it seems). Even if the script couldn't return any data, it should at least return an empty array, but when I open the file, it shows an empty page with no text at all. What am I doing wrong?
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Retrieve all rows from the database
$sql = "SELECT * FROM u8338p5759_iosdb.Posts";
$result = $conn->query($sql);
$dataArray = Array();
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
// Assign each row into an array
$dataArray[] = $row;
}
echo json_encode($dataArray);
} else {
echo json_encode($dataArray);
}
// Close the connection
$conn->close();
$row * $result->fetch_assoc()to$row = $result->fetch_assoc()and make sure $conn is established.$conn = new mysqli('localhost', 'root', '', 'test');Full code is working. Nice :)