Last active
January 3, 2016 04:29
-
-
Save isner/8408834 to your computer and use it in GitHub Desktop.
Function that takes your mysqli connection object and a query string and returns a mysql result object
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Performs a database query using PHP's MYSQLI class | |
// Returns a result object if successful | |
// Else dies and displays the SQL error and the query string that failed | |
function db_query($mysqli, $sql) { | |
$result = $mysqli->query($sql); | |
if (!$result) { | |
$message = "SQL error: ".$mysqli->errno." ".$mysqli->error.'<br>'; | |
$message.= "Failed query: ".$sql; | |
die($message); | |
} else { | |
return $result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment