Here are two simple PHP functions to add to your libraries. Replace the localhost, user, password and database names with your information. Need this code in Object-oriented format? Just let us know and we can supply that, too.
// Create a connection to our database
function sql_connect() {
$dbhost = 'localhost';
$dbuser = 'user';
$dbpass = 'password';
$conn = mysql_connect($dbhost,$dbuser,$dbpass);
if($conn) {
return $conn;
}else{
header('Location: 500.php');
}
}
// Perform our queries
function sql_query($query) {
$dbname = 'database';
$conn = sql_connect();
mysql_select_db($dbname, $conn);
$result = mysql_query($query, $conn);
if (!$result){
// The @ symbol supresses error messages from functions, use error supression in a live environment!
// @die("invalid query -- $query -- " . mysql_error());
header('Location: index.php');
}
return $result;
}





