php mysql问题 数据库连接成功执行析构函数后 后面的代码不执行什么原因
<?php
/*
* class mysql
*/
class mysql_class
{
public $host;
public $root;
public $passwd;
public $database;
public $ut;
public $link;
////construct
function __construct($host,$root,$passwd,$database,$ut)
{
$this->host = $host;
$this->root = $root;
$this->passwd = $passwd;
$this->database = $database;
$this->ut = $ut;
$this->connect();
}
////destruct
function __destruct()
{
echo $this->link;
mysql_close($this->link);
echo "destruct<br />";
}
////mysql connect
function connect()
{
$this->link = mysql_connect($this->host,$this->root,$this->passwd);
if(!$this->link)
{
die("Could not connect".mysql_error()."<br />");
}
else {
echo "Connect successed<br />";
}
mysql_select_db($this->database,$this->link) or die("No Database:".$this->database."<br />");
mysql_query("SET NAME 'UTF8'");
}
}
////执行下面test1
////或执行下面test2
?>
执行test1:代码
////test1
$ms = new mysql_class("localhost","admin","admin","php1000","UTF8");
$ms = null;
echo '<br />mysqlclass end== <br />';
$con = mysql_connect ( "localhost", "admin", "admin" );
if (! $con) {
die ( 'Could not connect: ' . mysql_error () );
}
else{
echo "<br />11connect successed";
}
echo $con."==con<br />";
// 一些代码...
mysql_close($con);
//test1结果如下:(为啥结果里没有11connect successed Resource id #3==con这些内容输出)
Connect successed
No Database:php1000
Resource id #3destruct
执行test2:
////test2 代码
$con = mysql_connect ( "localhost", "admin", "admin" );
if (! $con) {
die ( 'Could not connect: ' . mysql_error () );
}
else{
echo "<br />11connect successed<br />";
}
echo $con."==con<br />";
// 一些代码...
mysql_close($con);
$ms = new mysql_class("localhost","admin","admin","php1000","UTF8");
$ms = null;
echo '<br />mysqlclass end== <br />';
//test2 结果:
11connect successed
Resource id #3==con
Connect successed
No Database:php1000
Resource id #5destruct
免责声明: 本文仅代表作者个人观点,与爱易网无关。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。