CopyCode The Code is as follows: <? PHP
Class dB {
VaR $ host_addr = "localhost ";
VaR $ host_user = "root ";
VaR $ host_psw = "123 ";
VaR $ db_name = "test ";
VaR $ link_id;
VaR $ query_id;
VaR $ numrow;
Function dB (){
$ This-> link_id = @ mysql_connect ($ this-> host_addr, $ this-> host_user, $ this-> host_psw );
If ($ this-> link_id ){
@ Mysql_select_db ($ this-> db_name, $ this-> link_id) or $ this-> halt ("database connection failed! ");
} Else {
$ This-> halt ("failed to connect to the server! ");
Return false;
}
Return $ this-> link_id;
}
Function query ($ SQL ){
$ This-> query_id = @ mysql_query ($ SQL, $ this-> link_id );
If ($ this-> query_id ){
Return $ this-> query_id;
} Else {
$ This-> halt ("SQL error ::");
Return false;
}
}
Function numrow (){
Return $ this-> numrow = @ mysql_num_rows ($ this-> query_id );
}
Function close (){
Return @ mysql_close ($ this-> link_id );
}
Function halt ($ MSG ){
Echo "<font color = \" # ff0000 \ ">". $ msg. "</font> ";
}
}
?>