Error connecting to DB"); email_error("Connection Error",mysql_error()); } $result = mysql_query($sql); if (mysql_errno() == 0){ return $result; }else{ email_error($sql,mysql_error()); $result = 'Null'; } }//end function function email_error($reason, $error) { $headers = "MIME-Version: 1.0\n"; $headers .= "Content-type: text/plain; charset=iso-8859-1\n"; $headers .= "X-Priority: 3\n"; $headers .= "X-MSMail-Priority: Normal\n"; $headers .= "X-Mailer: php\n"; $headers .= "From: \"".$from."\" <".$from.">\n"; $sendto = "me@mydomain.com"; $subject = "Db error notification"; $time = date("Y-m-d H:m"); $message = "Application db interface failed at $time.\n\n Operation : $reason\n\n MySQL Error: $error \n\n User: ".$_SESSION['username']."\n\n Regards, System"; mail($sendto, $subject, $message, $headers); die("
There was a problem with the database"); } ?> To use this file, you include it and then simply call the function CODE FOR IMPLEMENTAION IN ASSOCIATED FILES //include conn file require("config/conn.php"); //more of your code $sql = "select * from tableName [where][group by][order by]"; // get the regular listing results $result = connect($sql); if ($result){ //show the results }else{ //handle failure in some way } ?>