I am using the following code to connect to my local database and query results from a table. The following code is not working to print my results in a JSON format. Is there something I am missing? Thanks for your help!
<?php
if (!$link = mysql_connect('localhost', 'root', 'root')) {
echo 'Could not connect to mysql';
exit;
}
if (!mysql_select_db('tm-charts', $link)) {
echo 'Could not select database';
exit;
}
$sql = 'SELECT Name,status FROM Estimates';
$result = mysql_query($sql, $link);
if (!$result) {
echo "DB Error, could not query the database\n";
echo 'MySQL Error: ' . mysql_error();
exit;
}
$rows = array();
while ($row = mysql_fetch_assoc($result)) {
$rows[] = $row;
}
echo json_encode($rows);
?>