I have this class called dataBase
. Looks like this
class dataBase
{
private $conexion;
private $paisConexion;
var $db;
function __construct($db='default')
{
$this->db = $db;
include '../settings/variables.php';
if(isset($bbdd)){
$conexion = mysql_connect($bbdd["server"], $pais[0]['user'], $pais[0]['pass']) or die('No se pudo conectar: '.mysql_error());
// Seleccionamos la base de datos
mysql_select_db($x[0]['database']) or die('No se pudo seleccionar la base de datos');
if($conexion)
{
$paisConexion = mysql_connect($bbdd["server"], $pais[$this->db]['user'], $pais[$this->db]['pass']) or die('No se pudo conectar: '.mysql_error());
mysql_select_db($pais[$this->db]['database']) or die('No se pudo seleccionar la base de datos');
}
}
else{
echo 'El sistema no se pudo conectar a la base de datos.';
exit;
}
}
public function execute($sql)
{
$result = mysql_query($sql) or die("ERROR: Ejecución de consulta: $sql<br>
");
return $result;
}
}
I am trying to make two connection to two different database using the variable $conexion
and $paisConexion
.
My question is is it possible to do something like this .
I mean suppose I am creating an object for the class like this
$obj = new dataBase(1);
$res = obj->execute($sql);
So how the the class will decide which of the connection it has to use ? .
I think I am doing this wrong way . If any one has any idea please let me know
Thanks in Advance