Copy codeThe Code is as follows: class mysql {
Function connect ($ dbhost, $ dbuser, $ dbpw, $ dbname = '', $ dbcharset = ''){
If (! @ Mysql_connect ($ dbhost, $ dbuser, $ dbpw )){
$ This-> show ('can not connect to MySQL Server ');
}
If ($ dbname ){
$ This-> select_db ($ dbname );
}
If ($ this-> version ()> '4. 1 '){
If ($ dbcharset ){
$ This-> query ("set names '". $ dbcharset ."'");
}
}
}
Function select_db ($ dbname ){
Return mysql_select_db ($ dbname );
}
Function fetch_array ($ query, $ result_type = MYSQL_ASSOC ){
Return @ mysql_fetch_array ($ query, $ result_type );
}
Function query ($ SQL, $ type = ''){
If (! ($ Query = mysql_query ($ SQL) $ this-> show ('mysql Query error', $ SQL );
Return $ query;
}
Function affected_rows (){
Return mysql_affected_rows ();
}
Function result ($ query, $ row ){
Return mysql_result ($ query, $ row );
}
Function num_rows ($ query ){
Return @ mysql_num_rows ($ query );
}
Function num_fields ($ query ){
Return mysql_num_fields ($ query );
}
Function free_result ($ query ){
Return mysql_free_result ($ query );
}
Function insert_id (){
Return mysql_insert_id ();
}
Function fetch_row ($ query ){
Return mysql_fetch_row ($ query );
}
Function version (){
Return mysql_get_server_info ();
}
Function close (){
Return mysql_close ();
}
Function show ($ message = '', $ SQL = ''){
If (! $ SQL) echo $ message;
Else echo $ message. '<br>'. $ SQL;
}
}
Class page extends mysql {
Function pagination ($ SQL, $ maxnum, $ page, $ maxpages, $ pagepre, $ ext = ''){
Global $ sum, $ stail, $ link, $ lmid, $ ltail, $ curpage; // $ ext = '& class = 3'
$ SELF = $ _ SERVER ['php _ SELF '];
$ Query = $ this-> query ($ SQL );
$ Rows = $ this-> fetch_array ($ query, MYSQL_NUM );
$ Totalrows = $ rows [0];
$ Totalpages = ceil ($ totalrows/$ maxnum );
$ Startnum = ($ page-1) * $ maxnum;
$ String = $ sum. $ totalrows. $ stail. $ sum. $ page. "/". $ totalpages. $ stail;
If ($ page! = 1 ){
$ String. = $ link. $ SELF ."? Page = 1 ". $ ext. $ lmid." | updated ". $ ltail;
$ String. = $ link. $ SELF .'? Page = '. ($ page-1). $ ext. $ lmid. "commandid". $ ltail;
}
If ($ maxpages >=$ totalpages ){
$ Pgstart = 1; $ pgend = $ totalpages;
}
Elseif ($ page-$ pagepre-1 + $ maxpages)> $ totalpages ){
$ Pgstart = $ totalpages-$ maxpages + 1;
$ Pgend = $ totalpages;
}
Else {
$ Pgstart = ($ page <= $ pagepre )? 1 :( $ page-$ pagepre ));
$ Pgend = ($ pgstart = 1 )? $ Maxpages :( $ pgstart + $ maxpages-1 ));
}
For ($ pg = $ pgstart; $ pg <= $ pgend; $ pg ++ ){
If ($ pg = $ page ){
$ String. = $ curpage. $ SELF ."? Page = ". $ pg. $ ext. $ lmid. $ pg. $ ltail;
}
Else $ string. = $ link. $ SELF ."? Page = ". $ pg. $ ext. $ lmid. $ pg. $ ltail;
}
If ($ page! = $ Totalpages ){
$ String. = $ link. $ SELF .'? Page = '. ($ page + 1). $ ext. $ lmid. "›". $ ltail;
$ String. = $ link. $ SELF .'? Page = '. $ totalpages. $ ext. $ lmid. "› |". $ ltail;
}
Return $ string;
}
}
Function html ($ str ){
$ Str = get_magic_quotes_gpc ()? $ Str: addslashes ($ str );
Return $ str;
}
Function dehtml ($ str ){
$ Str = nl2br (stripslashes ($ str ));
Return $ str;
}
Function deip ($ str ){
$ Arr = explode ('.', $ str );
$ Str = $ arr [0]. '.'. $ arr [1]. '.'. $ arr [2]. '. *';
Return $ str;
}