Basically I am trying to create a class to handle Database connections. I have double checked to make sure that my connection variables are correct and they work if I plug them directly into the PHP page. But when I call the class like this:
require_once __DIR__ . 'includes/db_connect.php';
$db = new DB_CONNECT();
It doesn't work. Here is my code. Maybe I am missing something.
<?php
// Class file to connect to database
class DB_CONNECT {
// constructor
function __construct()
{
// connection to database
$this->connect();
}
// destructor
function __destruct()
{
// disconnecting from database
$this->close();
}
// Function for Database Connection
function connect()
{
// import database connection variables
require_once _DIR_ . '/db_config.php';
// connection to mysql database
$con = mysql_connect(DB_SERVER, DB_USER, DB_PASSWORD) or die (mysql_error());
// selecting database
$db = mysql_select_db(DB_DATABASE) or die (mysql_error()) or die (mysql_error());
// returning connection cursor
return $con;
}
// Function to close db connection
function close()
{
// closing db connection
mysql_close();
}
}
?>