/*
* 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 '");
}
}
Perform the following test1
or perform the following test2
?>
Execute Test1: Code
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
";
Some code ...
Mysql_close ($con);
Test1 results are as follows: (why there is no 11connect successed Resource ID in the result #3 ==con these content output)
Connect successed
No database:php1000
Resource ID #3destruct
Execution Test2:
Test2 Code
$con = mysql_connect ("localhost", "admin", "admin");
if (! $con) {
Die (' Could not connect: '. Mysql_error ());
}
else{
echo "
11connect successed
";
}
echo $con. " ==con
";
Some code ...
Mysql_close ($con);
$ms = new Mysql_class ("localhost", "admin", "admin", "php1000", "UTF8");
$ms = null;
Echo '
Mysqlclass end==
';
Test2 results:
11connect successed
Resource ID #3 ==con
Connect successed
No database:php1000
Resource ID #5destruct
Reply to discussion (solution)
mysql_select_db ($this->database, $this->link) or Die ("No database:". $this->database. "
");
Since the output of No database:php1000
It means that your program is finished prematurely, the content is not executed, and there is no output.
Thanks for the big God's reminder upstairs.