I use this php code to connect to my databse and retrieve the table food. I am able to connect to the database but no retrieve the table. I get this as a result: Host information: site.ipagemysql.com via TCP/IP Default database is database. Is there something wrong with my code?
<?php
$mysqli = new mysqli("site.ipagemysql.com", "user", "pass", "database");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
printf("Host information: %s\n", $mysqli->host_info);
$result = mysqli_query($mysqli, "SELECT DATABASE()");
$row = mysqli_fetch_row($result);
echo "<br />";
printf("Default database is %s.\n", $row[0]);
$query = "SELECT * FROM example";
$result2 = mysqli_query($mysqli,$query) or die(mysql_error());
while($row2 = mysqli_fetch_array($result2, MYSQLI_BOTH)){
echo $row2['food']. " - ". $row2['calories'];
echo "<br />";
}
?>