Database connection
Posted: Fri May 11, 2007 5:30 am
database.php
I have two classes that connects to two different database.
I face some problem when i tried to create two object at the same time.
Should I create the object only when I wants to make a query to the database and close it after the query ?
I have a feeling mysql does not allow me to open two or more connection simultaniously.
Code: Select all
class MySQLDB
{
var $connection;
function MySQLDB(){
$this->connection = mysql_connect(DB_SERVER,DB_USER,DB_PASS) or die ("Could not connect to MySQL");
mysql_select_db("db1", $this->connection) or die(mysql_error());
}
function query($query){
$result = mysql_query($query, $this->connection);
if (!$result) {
die('Invalid query: ' . mysql_error());
}else
return $result;
}
}
class MySQLDB2
{
var $connection;
function MySQLDB2(){
$this->connection = mysql_connect(DB_SERVER,DB_USER,DB_PASS) or die ("Could not connect to MySQL");
mysql_select_db("db2", $this->connection) or die(mysql_error());
}
function query($query){
$result = mysql_query($query, $this->connection);
if (!$result) {
die('Invalid query: ' . mysql_error());
}else
return $result;
}
}
$database = new MySQLDB;
$database2 = new MySQLDB2;I face some problem when i tried to create two object at the same time.
Should I create the object only when I wants to make a query to the database and close it after the query ?
I have a feeling mysql does not allow me to open two or more connection simultaniously.