Here is a simple php class for working with database. The problem with this class is in __destruct
method, that launch mysql_close
function.
If I create two DB objects that are situated in code very close it cause an error. It looks like that mysql_close close all database connections, not just his own($this->dbLink). Why it is happens?
require_once("modules/required/OptionsReader/m_OptionsReader.php");
class DB{
private $dbLink;
public function __construct() {
$options = new OptionsReader();
$DBSettings = $options->getDBSettings();
$this->dbLink = mysql_connect($DBSettings->getAddress(),$DBSettings->getUserName(),$DBSettings->getPswd());
@mysql_select_db($DBSettings->getDBName()) or die( "Unable to select database");
mysql_query( "set names 'utf8'" );
}
public function __destruct() {
mysql_close($this->dbLink);
}
public function launchQuery($query){
return mysql_query($query);
}
}
?>
P.S. Ben bu sorunun basit bir çözüm sadece __ desctuctor close () fonksiyonu yapmak ve elle başlatmak olduğunu biliyorum, ama ne olup bittiğini anlamak için harika olacak. Teşekkür ederim