Well I personally built my own database connection functions which I use all the time.
They go like this;
// Function to open a database connection
function OpenDB(){
$dbh=mysql_connect ("localhost", "$username", "$password")
or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("$db");
return $dbh;
}
// Function to close a database connection
function CloseDB($dbh){
mysql_close($dbh);
}
// Then I set an includes to the file with the function list as follows;
include 'includes/functions.php';
// Then I call my OpenDB function
$dbh = OpenDB();
// Then I run my mysql query and extract the data
$query = "SELECT * FROM table WHERE id >5";
$result = mysql_query($query);
while($row = mysql_fetch_array($result)){
$fieldname = $row['fieldname'];
$fieldname2 = $row['fieldname2'];
echo $fieldname . ' - ' . $fieldname2 . ' <br> ';
}
// Then I close the database
CloseDB($dbh); |