Is there a more efficient way to write this? This script will be used heavily and I want to make sure I do not have any memory leaks or speed issues.
This script gets an input from a form and searches the database for that record.
<?php
date_default_timezone_set('America/Los_Angeles');
$hostname='xxx';
$username='xxx';
$password='xxx';
$dbname='xxx';
$db = mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.');
mysql_select_db($dbname);
$input_id = $_POST['id'];
$sql = "SELECT chart_id, CONCAT(first_name,' ',last_name) as full_name, expiration_date as exp, NOW() as now, DATE_FORMAT(date_of_birth,'%m-%d-%Y') as date_of_birth, DATE_FORMAT(expiration_date,'%M %d, %Y') as expiration_date, DATE_FORMAT(recommendation_date,'%M %d, %Y') as recommendation_date, notes
FROM chart
WHERE chart_id = '" . mysql_real_escape_string($input_id) . "'
";
$today = date("F j, Y");
$result = mysql_query($sql) or die(mysql_error());
if (mysql_num_rows($result) > 0) {
$row = mysql_fetch_assoc($result);
if ($row['exp'] < $row['now']) {
$row['status'] = 0;
}
else {
$row['status'] = 1;
}
mysql_free_result($result);
}
else {
$row['status'] = 'none';
}
mysql_close($db);
?>
$row['status'] = (int) ($row['exp'] >= $row['now']);\$\endgroup\$