The Code is as follows:
<? Php <br/> class mysqlclass <br/> {<br/> function mysqlclass ($ host = 'localhost', $ user = 'root', $ PW = '', $ db = 'mysql') <br/>{< br/> $ this-> link = mysql_connect ($ host, $ user, $ PW ); <br/> mysql_select_db ($ dB); <br/>}< br/> function query ($ SQL) {<br/> mysql_query ($ SQL ); <br/>}< br/> function _ destruct () {<br/> mysql_close ($ this-> link ); // multi construct will cause error <br/>}</P> <p >}< br/> $ db = new mysqlclass (); <br/> $ db = new mysqlclass (); <br/> $ db-> query ("select * from user ");
Cause:
When mysqlclass is first made into mysqlclass for the second time, get the same $ this-> link as the first $ dB, call the _ construct function to disable this-> link.
The MySQL resource in $ db is empty. Pop-up error
Solution:
$ Db = $ DB? $ DB: New mysqlclass ();
Or
$ This-> link = mysql_connect ($ host, $ user, $ PW, true );