Ciao,
ho creato una classe di supporto per gestier le connessioni a mysql ma quando creo istanze multiple l'unica connessione che rimane attiva è l'ultima, qualcuno sa spiegarmi il perchè? (PHP 5.3)
Di seguito il codidce che mi stampa solo le tabelle dell'ultima connessione creata.....
Codice PHP:
class EntityManager {
public $host;
public $schemaName;
public $username;
public $password;
public $persistent;
public $connection;
public function __construct($host, $schema, $username, $password, $persistent = false) {
$this->host = $host;
$this->schemaName = $schema;
$this->username = $username;
$this->password = $password;
$this->persistent = $persistent;
if ($this->persistent){
$this->connection = mysql_pconnect( $this->host, $this->username, $this->password );
if ( !mysql_ping( $this->connection ) ){
$this->connection = mysql_pconnect( $this->host, $this->username, $this->password );
}
} else {
$this->connection = mysql_connect( $this->host, $this->username, $this->password );
}
mysql_set_charset('utf8',$this->connection);
if (!$this->connection) {
die('Could not connect: ' . mysql_error($this->connection));
}
if (!mysql_select_db($this->schemaName, $this->connection)) {
die("Unable to select mydbname: " . mysql_error($this->connection));
}
}
public function close(){
mysql_close($this->connection);
}
public function selectTables(){
$result = $this->execQuery("SHOW TABLES");
while($table = mysql_fetch_array($result)){
echo $table[0].'
';
}
mysql_free_result($result);
}
....
}
$emTest = new EntityManager($db_host, $test_db_name, $test_db_user, $test_db_password);
$emPro = new EntityManager($db_host, $db_schema, $db_user_name, $db_password);
$emTest->selectTables();
$emPro->selectTables();