Data manipulation Phpfans The data manipulation classes and pagination classes used in the message edition

Source: Internet
Author: User
Tags mysql query
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.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.