Copy codeThe 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> ";
}
}
?>