php mysql有关问题 数据库连接成功执行析构函数后 后面的代码不执行什么原因
程序员文章站
2024-01-16 14:30:46
...
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
/*
* 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
专题推荐
-
独孤九贱-php全栈开发教程
全栈 170W+
主讲:Peter-Zhu 轻松幽默、简短易学,非常适合PHP学习入门
-
玉女心经-web前端开发教程
入门 80W+
主讲:灭绝师太 由浅入深、明快简洁,非常适合前端学习入门
-
天龙八部-实战开发教程
实战 120W+
主讲:西门大官人 思路清晰、严谨规范,适合有一定web编程基础学习
- 最新文章
- 热门排行
网友评论
文明上网理性发言,请遵守 新闻评论服务协议
我要评论