一个简单的可以实现分页的SqlHelper类
来源:互联网 发布:附近淘宝店 编辑:程序博客网 时间:2024/05/20 01:38
SqlHelper.class.php
<?php
Class SqlHelper{
public $conn;
public $reslt;
private $ip="localhost";
private $name="root";
private $password="root";
private $dbName="datebase02";
public function getConnect(){
$this->conn=mysql_connect($this->ip,$this->name,$this->password);
if(!$this->conn){
echo "mysql连接失败,请检查数据库连接信息是否正确!".mysql_error();
exit();
}
if(!mysql_select_db($this->dbName,$this->conn)){
echo "mysql 指定数据库失败,请检查数据库是否存在!";
exit();
}
if(!mysql_set_charset("utf8",$this->conn)){
echo "指定字符集失败,程序退出!";
}
}
//执行dql操作,返回一个结果集
public function dql($sql){
$this->reslt=mysql_query($sql,$this->conn);
if(!$this->reslt){
echo "执行sql语句失败".$sql;
exit();
}
return $this->reslt;
}
//执行dql操作,返回一个数组
public function dqlArray($sql){
$array=Array();
$this->reslt=mysql_query($sql,$this->conn);
if(!$this->reslt){
echo "执行sql语句失败".sql;
exit();
}
$i=0;
while($row=mysql_fetch_assoc($this->reslt)){
$i++;
$array[$i]=$row;
}
mysql_free_result($this->reslt);
return $array;
}
//执行dql操作,用于分页
public function dqlPage($sql1,$sql2,$paging){
$array=Array();
$this->reslt=mysql_query($sql1,$this->conn);
if(!$this->reslt){
echo "执行sql语句失败".$sql1;
exit();
}
while($row=mysql_fetch_assoc($this->reslt)){
$array[]=$row;
}
mysql_free_result($this->reslt);
$paging->setRow_array($array);
$this->reslt=mysql_query($sql2,$this->conn);
if(!$this->reslt){
echo "执行sql语句失败".$sql2;
exit();
}
while ($row=mysql_fetch_row($this->reslt)){
$paging->setPageCount(ceil($row[0]/$paging->getPageSize()));
$paging->setRow_count($row[0]);
}
mysql_free_result($this->reslt);
//进行判断能否切换上一页
if($paging->getPageCurrent()>1){
$paging->setNavigation("<a href='PageUIController.php?pageCurrent=".($paging->getPageCurrent()-1)."'>上一页</a> ");
}else{
$paging->setNavigation("<a href='PageUIController.php?pageCurrent=".($paging->getPageCurrent())."'>上一页</a> ");
}
//进行判断能否切换下一页
if($paging->getPageCurrent()<$paging->getPageCount()){
$paging->setNavigation($paging->getNavigation()."<a href='PageUIController.php?pageCurrent=".($paging->getPageCurrent()+1)."'>下一页</a> ");
}else{
$paging->setNavigation($paging->getNavigation()."<a href='PageUIController.php?pageCurrent=".($paging->getPageCurrent())."'>下一页</a> ");
}
$paging->setNavigation($paging->getNavigation()."当前页[".$paging->getPageCurrent()."]/共有[".$paging->getPageCount()."]页");
}
//执行dml操作
public function dml($sql){
$this->reslt=mysql_query($sql,$this->conn);
if(!$this->reslt){
return 0; //执行失败
}
if(mysql_num_rows($this->reslt)>0){
return 1; //执行成功
}else{
return 2; //没有受影响行数
}
}
//关闭数据库
public function close(){
mysql_close($this->conn);
}
}
分页实体类
paging.class.php
<?php
Class Paging{
private $pageSize; //每一页所显示的行数
private $pageCurrent; //当前页
private $row_array; //分页所显示的内容数组
private $row_count; //总共有多少条记录
private $pageCount; //可以分多少行
private $navigation; //导航条
/**
* @return the $navigation
*/
public function getNavigation() {
return $this->navigation;
}
/**
* @param field_type $navigation
*/
public function setNavigation($navigation) {
$this->navigation = $navigation;
}
/**
* @return the $pageSize
*/
public function getPageSize() {
return $this->pageSize;
}
/**
* @return the $pageCurrent
*/
public function getPageCurrent() {
return $this->pageCurrent;
}
/**
* @return the $row_array
*/
public function getRow_array() {
return $this->row_array;
}
/**
* @return the $row_count
*/
public function getRow_count() {
return $this->row_count;
}
/**
* @return the $pageCount
*/
public function getPageCount() {
return $this->pageCount;
}
/**
* @param field_type $pageSize
*/
public function setPageSize($pageSize) {
$this->pageSize = $pageSize;
}
/**
* @param field_type $pageCurrent
*/
public function setPageCurrent($pageCurrent) {
$this->pageCurrent = $pageCurrent;
}
/**
* @param field_type $row_array
*/
public function setRow_array($row_array) {
$this->row_array = $row_array;
}
/**
* @param field_type $row_count
*/
public function setRow_count($row_count) {
$this->row_count = $row_count;
}
/**
* @param field_type $pageCount
*/
public function setPageCount($pageCount) {
$this->pageCount = $pageCount;
}
}
- 一个简单的可以实现分页的SqlHelper类
- 简单的sqlHelper类
- SqlHelper类的实现
- 一个简单的分页类
- 一个简单的分页类
- hibernate+spring的一个简单分页实现
- hibernate+spring的一个简单分页实现
- hibernate+spring的一个简单分页实现
- hibernate+spring的一个简单分页实现
- 前端实现一个简单的表格分页
- 从零开始实现一个简单的分页
- vuejs2.0实现一个简单的分页
- vuejs2.0实现一个简单的分页
- 【C#】 简单的SQLHelper
- 可以切换数据库的SqlHelper
- js实现的分页组件 简单可以扩展
- 一个简单的分页
- 一个简单的分页
- 【hibernate框架】性能优化之session.clear()的运用和Java内存泄露问题
- Git常用指令集合
- 利用CIDetector来人脸识别
- 机器学习演算法 第四讲 Feasibility of Learning——学习笔记k
- 解决 Visual Studio Debugger Just-In-Time Debugging
- 一个简单的可以实现分页的SqlHelper类
- Thinking in Java学习笔记
- CF 518C(Anya and Smartphone-映射)
- 黑马程序员--String类的知识
- Linux增强系统安全性:防止单用户模式(single)修改密码
- zoj 3228 Searching the String (ac自动机)
- POJ 3321 Apple Tree(树状数组)
- NSUserDefaults
- ecshop Ajax.call的使用