PHP Code:
#----------------------------------------#
# Functions: #
# DB Functions #
#----------------------------------------#
function dbcon() { #Obviously, this connects to the SQL server, using the values from qzconfig.php
global $dbhost, $dbuser, $dbpass, $db;
$sql_server = @mysql_connect($dbhost,$dbuser,$dbpass)
or die("<b>Fatal Error:</b><br /><b>MYSQL:</b> Unable to connect to mySQL server.");
mysql_select_db($db,$sql_server)
or die("<b>Fatal Error:</b><br /><b>MYSQL:</b> Unable to query mySQL server.");
}
function dbquery($sql) { #For custom queries
global $result, $querycount;
$result = mysql_query($sql) or die("Your SQL query: <br />$sql<br /><br />MySQL said:<br />".mysql_error());
$querycount++;
}
Is what I use to make DB connections and queries. Its a tad shorter than Steve's but you are shorting yourself of the ordering and such. (Which IMO is actually better, because I'd rather be able to control the exact DB Query.... but thats just me)
Call dbcon(); then dbquery('SQL QUERY');
I also have an additional config file to insert the variables, but I don't think you want my password.
