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. '
'. $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." | ‹ ". $ltail;
$string. = $link. $SELF. '? Page= '. ($page-1). $ext. $lmid. " ‹‹ ". $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;
}
The above describes the data operation Phpfans Message version of the data manipulation class and paging class, including the data manipulation aspects, I hope that the PHP tutorial interested friends helpful.