phpfans留言版用到的数据操作类和分页类

时间:2021-05-26

复制代码 代码如下:classmysql{
functionconnect($dbhost,$dbuser,$dbpw,$dbname='',$dbcharset=''){
if(!@mysql_connect($dbhost,$dbuser,$dbpw)){
$this->show('CannotconnecttoMySQLserver');
}
if($dbname){
$this->select_db($dbname);
}
if($this->version()>'4.1'){
if($dbcharset){
$this->query("SETNAMES'".$dbcharset."'");
}
}
}

functionselect_db($dbname){
returnmysql_select_db($dbname);
}

functionfetch_array($query,$result_type=MYSQL_ASSOC){
return@mysql_fetch_array($query,$result_type);
}

functionquery($sql,$type=''){
if(!($query=mysql_query($sql)))$this->show('MySQLQueryError',$sql);
return$query;
}

functionaffected_rows(){
returnmysql_affected_rows();
}

functionresult($query,$row){
returnmysql_result($query,$row);
}

functionnum_rows($query){
return@mysql_num_rows($query);
}

functionnum_fields($query){
returnmysql_num_fields($query);
}

functionfree_result($query){
returnmysql_free_result($query);
}

functioninsert_id(){
returnmysql_insert_id();
}

functionfetch_row($query){
returnmysql_fetch_row($query);
}

functionversion(){
returnmysql_get_server_info();
}

functionclose(){
returnmysql_close();
}

functionshow($message='',$sql=''){
if(!$sql)echo$message;
elseecho$message.'<br>'.$sql;
}
}

classpageextendsmysql{
functionpagination($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."|&lsaquo;".$ltail;
$string.=$link.$SELF.'?page='.($page-1).$ext.$lmid."&lsaquo;&lsaquo;".$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."&rsaquo;&rsaquo;".$ltail;
$string.=$link.$SELF.'?page='.$totalpages.$ext.$lmid."&rsaquo;|".$ltail;
}
return$string;
}
}

functionhtml($str){
$str=get_magic_quotes_gpc()?$str:addslashes($str);
return$str;
}

functiondehtml($str){
$str=nl2br(stripslashes($str));
return$str;
}

functiondeip($str){
$arr=explode('.',$str);
$str=$arr[0].'.'.$arr[1].'.'.$arr[2].'.*';
return$str;
}

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章