Copy codeThe Code is as follows: class mysql
{
Private $ db; // datebase connect
Private $ result; // mysql result
Static private $ mysql; // mysql object
Private function _ construct ()
{// The work before Create an object
$ This-> db = mysql_connect ('localhost', 'root ','');
Mysql_select_db ('hello', $ this-> db );
}
Public static function getObject ()
{// If have a object, return that object, Not create
If (! Self: $ mysql instanceof self)
Self: $ mysql = new self;
Return self: $ mysql;
}
Public function query ($ SQL)
{
$ This-> result = mysql_query ($ SQL, $ this-> db );
Return $ this-> result;
}
Public function fetch ()
{
If (isset ($ this-> result ))
Return mysql_fetch_assoc ($ this-> result );
}
Public function error ()
{
Return 'error: '. mysql_error ();
}
Public function num () // for SQL select result
{
Return mysql_num_rows ($ this-> result );
}
Public function close ()
{// Return true or false
Return mysql_close ($ this-> db );
}
}
It seems that this operation is only useful for portability, and other functions cannot be realized.