rendered paste body//makes the connection to the MySql server and selects the database
//returns the connection ID
function DB_Connect()
{
$host = "localhost";
$username = "username";
$password = "password";
$dbname = "databasename";
debug_log("Opening Database Connection: $dbname", 4);
$dbconn = mysql_connect($host, $username ,$password) or die (debug_log("Failed Connecting to DB server: ". $host));
mysql_select_db($dbname, $dbconn) or die (debug_log("Failed Selecting Database: ". $dbname, 1));
return $dbconn;
}
//closes which ever database connection id is passed
function DB_Close($dbconn)
{
debug_log("Closing Database Connection: ". $dbconn, 5);
mysql_close($dbconn) or die (debug_log("Failed Closing Database: ". $dbconn, 1));
}
function db_query_array($strSQL)
{
global $Gdbconn;
$array = NULL;
debug_log("Executing SQL Query: '". $strSQL. "'", 4);
debug_log("Executing SQL Query on connection: ". $Gdbconn, 4);
$queryresult = mysql_query($strSQL, $Gdbconn) or die (debug_log("Failed Query: ". $strSQL, 1));
if ($queryresult != 1)
{
$length= mysql_num_rows($queryresult);
for($i=0; $i < $length; $i++)
{
$row= mysql_fetch_array($queryresult);
$array[$i]= $row;
}
mysql_free_result($queryresult);
}
debug_log("Executing SQL Query: Complete", 4);
return $array;
}
function debug_log($strMessage, $debuglevel)
{
global $Gdebug_level;
if ($debuglevel <= $Gdebug_level)
{
print($strMessage. "<br>\n");
}
}
$Gdebug_level = 0;
$Gdbconn = DB_Connect();
DB_Close($Gdbconn);