How would I properly handle a bad SQL string query? For example if the $table provided doesn't exist, the where expression is invalid, or the $field doesn't exist?
function GetMax($field, $table, $WhereExpression) {
$con = mysqli_connect(ServerHostName, ServerUser, ServerPass, ServerDB);
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
exit();
}
$q = "SELECT Max($field) AS MaxOfGetMax FROM $table WHERE $WhereExpression";
$rst = mysqli_query($con, $q);
if ($rst=false){
if ($row = mysqli_fetch_array($rst))
{
return $row["MaxOfGetMax"];
}
return null;
}
}