赋予1=1
var $showMessage; //操作返回的提示
var $pageCode = 1; //当前页,程序默认为1
var $pageSize = 10; //每页显示记录数,程序默认为10
var $pageUrl = '?'; //分页时传入的其它保留参数
var $pageViewText; //输出分页字符串
var $pageView = false; //是否显示分页,默认为不显示
var $bodyAry = Array(); //返回查询的数据
var $siteCode = Array( //返回提示的文字,目的:多语言
0 => '数据库连接成功!',
1 => '数据库连接失败!',
2 => '数据写入成功!',
3 => '数据更新成功!',
4 => '数据删除成功!',
5 => '数据查询失败!',
6 => '首页',
7 => '上一页',
8 => '下一页',
9 => '尾页'
);
//数据库连接
function conn(){
try {
$this->conn = new com("ADODB.Connection");
$this->conn->Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . realpath($this->dbPath));
$this->showMessage = $this->siteCode[0];
}
catch(Exception $e){
$this->showMessage = $e->getMessage() . '
' . $this->siteCode[1];
}
}
//数据库关闭
function conn_close(){
$this->conn->close();
}
//写入数据
function setData(){
$this->conn();
$this->conn->execute("insert into $this->tabName ($this->aryChar) values($this->aryText)");
$this->showMessage = $this->siteCode[2];
$this->conn_close();
}
//更新数据
function upData(){
$this->conn();
$this->conn->execute("update $this->tabName set $this->aryChar where $this->aryText");
$this-
>showMessage = $this->siteCode[3];
$this->conn_close();
}
//删除数据
function delData(){
$this->conn();
$this->conn->execute("delete from $this->tabName where $this->aryText");
$this->showMessage = $this->siteCode[4];
$this->conn_close();
}
//查询数据
function getData(){
$this->conn();
$rs = $this->conn->execute("select $this->aryChar from $this->tabName where $this->aryText");
if(!$rs->Eof){
$j = 0;
$k = 0;
if(!preg_match("/^\d+$/" , $this->pageCode)){
$this->pageCode = 1;
}
while(!$rs->Eof){
$j ++;
//把记录写进当前需要显示的二维数组中
if(($j > ($this->pageCode - 1) * $this->pageSize) &;&; ($j <= $this->pageCode * $this->pageSize)){
for($i = 0 ; $i < $rs->Fields->count ; $i ++){
$this->bodyAry[$k][$i] = $rs->Fields[$i]->value;
}
$k ++;
}
$rs->movenext();
}
//分页
if($this->pageView == true){
$this->pageViewText = '[' . $j . '][' . $this->pageCode . '/' . ceil($j / $this->pageSize) . ']&;nbsp;';
if($j > $this->pageSize){
if($this->pageCode > 1){
$this->pageViewText .= "
pageUrl . "page=1'>" . $this->siteCode[6] . "&;nbsp;";
$this->pageViewText .= "
pageUrl . "page=" . ($this->pageCode - 1) . "'>" . $this->siteCode[7] . "&;nbsp;";
}
else {
$this->pageViewText .= $this->siteCode[6] . "&;nbsp;";
$this->pageViewText .= $this->siteCode[7] . "&;nbsp;";;
}
if($this->pageCode < ceil($j / $this->pageSize)){
$this->pageViewText .= "
pageUrl . "page=" . ($this->pageCode + 1) . "'>" . $this->siteCode[8] . "&;nbsp;";
$this->pageViewText .= "
pageUrl . "page=" . ceil($j / $this->pageSize) . "'>" . $this->siteCode[9] . "";
}
else {
$this->pageViewText .= $this->siteCode[8] . "&;nbsp;";