


Data operation: data operation classes and paging classes used by phpfans message board
Copy the code The 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;
}
以上就介绍了数据操作 phpfans留言版用到的数据操作类和分页类,包括了数据操作方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to use PHP to implement batch processing and data batch operations. In the process of developing web applications, we often encounter situations where multiple pieces of data need to be processed at the same time. In order to improve efficiency and reduce the number of database requests, we can use PHP to implement batch processing and data batch operations. This article will introduce how to use PHP to implement these functions, and attach code examples for reference. Batch processing of data When you need to perform the same operation on a large amount of data, you can use PHP's loop structure for batch processing.

The JavaList interface is one of the commonly used data structures in Java, which can easily implement data addition, deletion, modification and query operations. This article will use an example to demonstrate how to use the JavaList interface to implement data addition, deletion, modification and query operations. First, we need to introduce the implementation class of the List interface in the code, the common ones are ArrayList and LinkedList. Both classes implement the List interface and have similar functions but different underlying implementations. ArrayList is based on array real

Qiniu Cloud Data Processing Management Guide: How does JavaSDK implement data operation and analysis? Introduction: With the advent of the big data era, data processing and analysis are becoming more and more important. As an enterprise focusing on cloud storage and data services, Qiniu Cloud provides a wealth of data processing and analysis functions to facilitate users to process and analyze massive data. This article will introduce how to use Qiniu Cloud's JavaSDK to implement data operations and analysis. 1. Preparation Before starting, we need to prepare some necessary tools and environment: Apply for Qiniu Cloud Account

How to use the features of PHP7 to achieve more flexible data operations and processing? With the release of PHP7, the PHP programming language has entered a new stage. PHP7 brings many exciting features, especially in data manipulation and processing, providing more flexibility and efficiency. This article will introduce how to use the features of PHP7 to achieve more flexible data operations and processing, as well as some specific code examples. Type declaration In PHP7, we can clarify the parameters and return value of a function or method by using type declaration

How to use arrays and collections for data storage and operation in Java In Java programming, arrays and collections are commonly used methods of data storage and operation. An array is a container used to store data of the same type, while a collection is an object composed of multiple elements. The basic method of using arrays for data storage and manipulation is as follows: Declaring an array variable To use an array, you first need to declare an array variable. An array variable can be declared using the following syntax: dataType[]arrayName; where dataT

How to use SQLAlchemy for database operations SQLAlchemy is a popular Python library used to simplify interaction and operation with relational databases. It provides an object-relational mapping (ORM) approach that allows developers to use Python code to operate the database without writing original SQL statements. This article will introduce how to use SQLAlchemy for database operations, and attach code examples to help readers get started quickly. Install SQLAlchemy first

In the MySQL database, data operation auditing is a very important task. Through the audit of data operations, changes in data in the database can be monitored in real time and abnormal operations can be discovered in a timely manner. This article will introduce data operation auditing techniques in MySQL to help readers better protect data security in the database. Using MySQL's native audit function MySQL provides a native audit function, which can be turned on through parameter settings to record every operation record in the database. The parameters to enable are as follows: log=

For data scientists and programmers, operators are essential tools in python for efficiently manipulating and analyzing data. From simple arithmetic operations to advanced logical comparisons, operators offer a wide range of possibilities for data processing tasks. Arithmetic Operators Arithmetic operators are used to perform basic mathematical operations. The most common arithmetic operators include addition (+), subtraction (-), multiplication (*), division (/), and modulus (%). The following examples demonstrate how to use arithmetic operators: #addition x=10+5 #subtraction y=15-7 #multiplication z=3*4 #division w=12/3 #modulo operation (remainder) r=10%3 Comparison Operators Comparison operators are used to compare two values and return a Boolean value (True or False). often
