phpfans留言版用到的数据操作类和分页类
程序员文章站
2023-10-28 16:11:16
复制代码 代码如下:class mysql{ func...
复制代码 代码如下:
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."|‹".$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;
}
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."|‹".$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;
}
推荐阅读
-
Python操作Oracle数据库的简单方法和封装类实例
-
phpfans留言版用到的数据操作类和分页类
-
MongoDB模糊查询操作案例详解(类关系型数据库的 like 和 not like)
-
MongoDB的模糊查询操作(类关系型数据库的 like 和 not like)
-
Python操作Oracle数据库的简单方法和封装类实例
-
MongoDB模糊查询操作案例详解(类关系型数据库的 like 和 not like)
-
数据操作 phpfans留言版用到的数据操作类和分页类
-
数据库操作的model类,用到了__call方法
-
MongoDB的模糊查询操作(类关系型数据库的 like 和 not like)
-
Python操作Oracle数据库的简单方法和封装类实例