该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
//adodb.php
class ADODB_ACCESS
{
var $Uid;
var $Pwd;
var $DataBase;
var $DataPath;
var $PathName;
var $DB_Address;
var $DSN;
var $Conn;
function AdodbConnection()
{
//连接用户名
$this->Uid = NULL;
//连接密码
$this->Pwd = NULL;
//数据库文件
$this->DataBase = "Test.mdb";
//数据库所在目录
$this->DataPath = "DataBase";
//得到当前目录
$this->PathName = str_replace('\\','\\',dirname(__FILE__));
//得到数据库目录
$this->DB_Address = $this->PathName."\\".$this->DataPath."\\".$this->DataBase;
//ADODB Access标准连接语句
$this->DSN = "Driver={Microsoft Access Driver (*.mdb)};Dbq=".$this->DB_Address.";Uid=".$this->Uid.";Pwd=;".$this->Pwd."";
//创建COM的实例
$this->Conn = new COM("ADODB.Connection") or die("Can't Connection DataBase Of Access !");
//打开数据库
$this->Conn->Open($this->DSN);
}
function AdodbClose()
{
$this->Conn->Close();
$this->Conn->Release();
$this->Conn = NULL;
}
}
?>
//class.php
include_once("ADODB.PHP");
class ExecuteSQL extends ADODB_ACCESS
{
//$StrSQL : 数据库查询字符串
//$PageSize : 每页显示记录数
//$PageNo : 为$_GET["PageNo"]
function SelectLimit($StrSQL,$PageSize,$PageNo)
{
//连接ACCESS
$this->AdodbConnection();
$Result = $this->Conn->Execute($StrSQL);
$ResultNum = $this->Conn->Execute($StrSQL);
$FieldsNum = $Result->Fields->Count();
//得到总记录
$Total = 0;
while(!$ResultNum->EOF)
{
$Total++;
$ResultNum->MoveNext();
}
//定义循环
$k = 0;
//定义页数
if(($Total%$PageSize)==0)
$MaxPage = (int)($Total/$PageSize);
else
$MaxPage = (int)($Total/$PageSize)+1;
if(empty($PageNo)) $PageNo = 1;
if($PageNo
if($PageNo > $MaxPage)$PageNo = $MaxPage;
//定义每页开始记录数
$StartPos = ($PageNo-1)*$PageSize;
$EndPos = $PageSize*$PageNo+1;
print("共有".$MaxPage."页".",".$Total."条记录,第".$PageNo."页,每页显示".$PageSize."条
");
//循环
while (!$Result->EOF)
{
//这里实现分页
//思路为:得到所有记录,但只打印当前页码的记录。
//PHP+ACCESS分页的方法很多,自己想想。
//我这个方法很笨,提示一种方法:
//
//将$StrSQL查询字符串改写,SelectLimit($StrSQL,$PageSize,$StartPage)可成为独立的函数
//例:$StrSQL="select * from cars order by id desc limit $StartPage,$PageSize"(MySQL)
// $StrSQL="select * from cars order by id desc where id>$StartPage and id
//
//E-Mail: Lovetidal@126.com
//OICQ : 3076622
//
if($k>=($StartPos) && $k
for ($i=0; $i
{
echo $Result->Fields[$i]->value." ";
}
echo "
";
}
$k++;
$Result->MoveNext();
}
//分页,自己改.
echo "< ";
$PageNo = $PageNo-1;
echo " ";
$PageNo = $PageNo+1;
echo "Next > ";
echo "Last >>";
//关闭连接
$this->AdodbClose();
}
}
?>
//default.php
include_once ('CLASS.PHP');
$a = new ExecuteSQL;
$a->SelectLimit("Select * From Cars","20",$PageNo);
?>
/*
说明:
COM+CLASS实现连接,并实现了翻页功能
*/