Thread: XML to MySQL
View Single Post
  #4   Spotlight this post!  
Unread 17-01-2003, 15:00
HFWang's Avatar
HFWang HFWang is offline
Registered User
AKA: DarkWulf
#0115
Team Role: Webmaster
 
Join Date: Jan 2003
Location: Cupertino
Posts: 177
HFWang will become famous soon enough
Send a message via ICQ to HFWang Send a message via AIM to HFWang
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.