I have a tendancy to try and put anything into a function - you'll never know when you will use it again....
My db connections always run through one...
<?php
global $db_user;
global $db_pass;
global $db_host;
global $db_name;
$db_user = '******';
$db_pass = '******';
$db_host = '192.168.150.10';
$db_name = 'ccs';
function do_query ( $sql )
{
ini_set("SMTP", "192.168.150.5");
$contactemail="me@here.com";
$subject="SQL Failure";
$content = "There has been a critical error with the SQL statement<br />";
$content .= "<br /><strong>".$sql."</strong><br /><br />";
$content .= "Made by ".@$_COOKIE['ccsuser']." on ".date("d M Y H:i:s",time());
$content .= "<br /><br />This was from page : ".$_SERVER['PHP_SELF'];
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: ME<someone@somewhere.com>\r\n";
$headers .= "To: ".$contactemail."\r\n";
$headers .= "Reply-To: Me<someone@somewhere.com>\r\n";
$headers .= "X-Priority: 1\r\n";
$headers .= "X-MSMail-Priority: High\r\n";
$headers .= "X-Mailer: Central Conference Services PHP Mailer";
global $db_user;
global $db_pass;
global $db_host;
global $db_name;
mssql_connect( $db_host, $db_user, $db_pass )or die("Cant connect to $db_host: ");
mssql_select_db( $db_name )or die("Cant select $db_name: ");
@$res = mssql_query( $sql )or die("There was an error - this has been logged!".mail($contactemail, $subject, $content, $headers));
return $res;
}
Means I can just give $query=do_query($sql); and if it works OK - if not I'll get mailed....
Simple yet very effective...
I know before my client if something goes wrong... Always good to be one step ahead...