I am completely new in PHP and MySQL but I need to make quick project for tomorrow. I do not know exactly where to find a solution for my problem because I do not know enough about this languages.
I will be glad if somebody will help me and find why I get blank page after that code:
<?php
$servername = "xyz.xyz";
$username = "123";
$password = "123";
$dbname = "123";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT `id`,`symbol`,`shortcut` FROM `Table`";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
$currencyArray = array();
while($row = $result->fetch_assoc()) {
$currency = array($row["id"], $row["symbol"], $row["shortcut"]);
$currencyArray[] = $currency;
}
print json_encode($currencyArray);
} else {
echo "0 results";
}
$conn->close();
?>
I want to display all data from the Table in JSON as an array with arrays that contains all data. Right now I have blank page. I will be glad for help.