1
任何人都可以解釋爲什麼mysql_close()從類析構函數調用失敗? mysql_error()報告「連接關閉失敗。」php mysql包裝類__destruct方法無法關閉數據庫
<?php
class Database
{
private $link_id = 0;
private $query_id = 0;
public $error = "";
public $errorNumber = 0;
public $affectedRows = 0;
public function __construct($server, $user, $pass, $database)
{
$this->link_id = @mysql_connect($server, $user, $pass, false);
if (!$this->link_id)
{
$this->DisplayError("Could not connect to server: <b>$this->server</b>.");
die(mysql_error());
}
if([email protected]_select_db($database, $this->link_id))
{
$this->DisplayError("Could not open database: <b>$this->database</b>.");
die(mysql_error());
}
}
public function __destruct()
{
if ($this->link_id)
{
if([email protected]_close($this->link_id))
{
$this->DisplayError("Connection close failed.");
die(mysql_error());
}
}
}
爲什麼不把它的「@」關掉,讓它實際記錄問題而不是掩蓋它? – dkamins 2011-06-03 00:15:44
'mysql_error()'報告什麼? – Phil 2011-06-03 00:16:26
@dkamins我正在使用自定義錯誤處理程序。 – Kevin 2011-06-03 00:18:00