Home > Backend Development > PHP Tutorial > php mysql有关问题 数据库连接成功执行析构函数后 后面的代码不执行什么原因

php mysql有关问题 数据库连接成功执行析构函数后 后面的代码不执行什么原因

WBOY
Release: 2016-06-13 12:30:56
Original
1452 people have browsed it

php mysql问题 数据库连接成功执行析构函数后 后面的代码不执行什么原因
/*
 * 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
";
}

////mysql connect
function  connect()
{
$this->link = mysql_connect($this->host,$this->root,$this->passwd);
 if(!$this->link)
 {
  die("Could not connect".mysql_error()."
");
 }
 else {
  echo "Connect successed
";
 }
 mysql_select_db($this->database,$this->link) or die("No Database:".$this->database."
");
 mysql_query("SET NAME 'UTF8'");
}
}

////执行下面test1 
////或执行下面test2


?>
执行test1:代码
////test1 
 $ms = new mysql_class("localhost","admin","admin","php1000","UTF8");
 $ms = null;
 echo '
mysqlclass end== 
';
 $con = mysql_connect ( "localhost", "admin", "admin" );
 if (! $con) {
  die ( 'Could not connect: ' . mysql_error () );
 }
 else{
  echo "
11connect successed";
 }
 echo $con."==con
";
 // 一些代码...
 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 "
11connect successed
";
 }
 echo $con."==con
";
 // 一些代码...
 mysql_close($con);
 $ms = new mysql_class("localhost","admin","admin","php1000","UTF8");
 $ms = null;
 echo '
mysqlclass end== 
';
 //test2 结果:
11connect successed
Resource id #3==con
Connect successed
No Database:php1000
Resource id #5destruct

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template