日韩天天综合网_野战两个奶头被亲到高潮_亚洲日韩欧美精品综合_av女人天堂污污污_视频一区**字幕无弹窗_国产亚洲欧美小视频_国内性爱精品在线免费视频_国产一级电影在线播放_日韩欧美内地福利_亚洲一二三不卡片区

帶數(shù)據(jù)緩存的ACCESS數(shù)據(jù)庫操作類(2)_Access數(shù)據(jù)庫教程

編輯Tag賺U幣
教程Tag:暫無Tag,歡迎添加,賺取U幣!

推薦:Access 2007數(shù)據(jù)庫添加附件
Access允許您在數(shù)據(jù)庫表中包含附件。通過利用微軟的對(duì)象鏈接和嵌入(OLE)技術(shù),您可以將照片、圖表、文檔及其他文件存儲(chǔ)在您的Access數(shù)據(jù)庫中。數(shù)據(jù)庫附件是Access 2007版本的一個(gè)新特

 

代碼:

以下為引用的內(nèi)容:

<?php
class access
{
/**
* 聲明存儲(chǔ)查詢結(jié)果ID的數(shù)組,數(shù)據(jù)庫連接ID,存儲(chǔ)分頁信息的數(shù)組,緩存數(shù)據(jù)讀取偏移量
*/
public $resultId, $linkId, $pageMsg, $offset;
/**
* 聲明顯示錯(cuò)誤消息的頁面地址
*/
public $errPage = '';
/**
* 聲明數(shù)據(jù)庫路徑,此路徑需為絕對(duì)路徑
*/
public $dbPath = '';

/**
* 緩存存儲(chǔ)路徑
*/
public $cachePath = '';

/**
* 緩存聲明周期,設(shè)為0則不適用緩存
*/
public $cacheLifeTime = 3600;

/**
* 當(dāng)使用分頁查詢時(shí),最多緩存多少頁
*/
public $cacheLimitMax = 100;

/**
* 建立數(shù)據(jù)庫連接
*
* 說明:
* 此數(shù)據(jù)庫類無構(gòu)造函數(shù),在聲明新類之后,需手動(dòng)運(yùn)行此函數(shù)
*/
public function connect()
{
$dsn = 'DRIVER={Microsoft Access Driver (*.mdb)}; DBQ='.$this->dbPath;
$this->linkId = odbc_connect($dsn,'','',SQL_CUR_USE_ODBC);
$this->linkId || $this->setError('Connect database defeat!');
}

/**
* 執(zhí)行一條SQL語句
*
* 參數(shù):
* $sql 要執(zhí)行的SQL語句
* $resultId 查詢結(jié)果的ID,當(dāng)執(zhí)行一條不需返回的SQL語句,如刪除,更新等時(shí),該參數(shù)可省略
*/
public function query($sql ,$resultId = '__id__')
{
$this->resultId[$resultId] = odbc_exec($this->linkId,$sql);
$this->resultId[$resultId] || $this->setError('Carries out the SQL defeat!');
}

/**
* 從查詢結(jié)果集中讀取一條記錄,并返回為數(shù)組
*
* 參數(shù):
* $resultId 查詢結(jié)果的ID
*/
public function record($resultId)
{
if (is_array($this->resultId[$resultId]))
{
$offset = $this->offset[$resultId]; $this->offset[$resultId] ;
return $this->resultId[$resultId][$offset];
}
return odbc_fetch_array($this->resultId[$resultId]);
}

/**
* 從查詢結(jié)果集中讀取一條記錄,并注冊(cè)為類的屬性,屬性名為字段名
*
* 參數(shù):
* $resultId 查詢結(jié)果ID
*/
public function recordObj($resultId)
{
if (is_array($this->resultId[$resultId]))
{
$rowArray = $this->resultId[$resultId][$this->offset[$resultId]];
$this->offset[$resultId] ;
} else {
$rowArray = $this->record($resultId);
}
for (reset($rowArray);$key = key($rowArray);next($rowArray)) $this->$key = $rowArray[$key];
}

/**
* 獲取一個(gè)查詢結(jié)果集的記錄數(shù)
*
* 參數(shù):
* $resultId 查詢結(jié)果ID
*/
public function rowsNum($resultId)
{
return odbc_num_rows($this->resultId[$resultId]);
}

/**
* 獲取表中符合條件的記錄總數(shù)
*
* 參數(shù):
* $table 表明
* $primary 主鍵,提供一個(gè)主鍵時(shí)可提高性能
* $condition 查詢條件,留空時(shí)將返回表中的記錄總數(shù)
*/
public function rowsTotal($table, $primary = '*', $condition = '')
{
$sql = 'select ('.$primary.') from '.$table.($condition ? ' where '.$condition : '');
$rowsTotal = odbc_result(odbc_exec($this->linkId,$sql),1);
$rowsTotal >= 0 || $this->setError('Gains the record total defeat!');
return (int)$rowsTotal;
}

/**
* 釋放一個(gè)查詢結(jié)果
*
* 參數(shù):
* $resultId 查詢結(jié)果ID
*/
public function resultFree($resultId)
{
odbc_free_result($this->resultId[$resultId]) || $this->setError('Release result defeat!');
}

/**
* 釋放所有查詢結(jié)果
*/
public function allResultFree()
{
for (reset($this->resultId);$key = key($this->resultId);next($this->resultId)) '__id__' == $key || $this->resultFree($key);
}

/**
* 釋放所有查詢結(jié)果并關(guān)閉數(shù)據(jù)庫連接
*/
public function close()
{
$this->allResultFree(); odbc_close($this->linkId);
}

/**
* 數(shù)據(jù)庫查詢
*
* 參數(shù):
* $resultId 查詢結(jié)果ID
* $table 所要查詢的數(shù)據(jù)表
* $fields 需要返回的字段,省略時(shí)將返回所有字段
* $condition 查詢條件,省略時(shí),將返回表中的所有記錄
*/
public function select($resultId, $table, $fields = '*', $condition = '')
{
if ($this->cacheLifeTime)
{
$cachePath = $this->cachePath.$table.md5($fields.$condition).'.php';
if (time() - @filemtime($cachePath) < $this->cacheLifeTime)
{
include $cachePath; $this->resultId[$resultId] = $dataCache;
$this->offset[$resultId] = 0; return;
} else {
$writeCache = true;
}
}
$condition && $condition = 'order ' == substr($condition,0,6) ? $condition : ' where '.$condition;
$this->query('select '.$fields.' from '.$table.$condition,$resultId);
$writeCache && $this->writeCache($cachePath,$resultId);
}

/**
* 插入記錄
*
* 參數(shù):
* $table 表明
* $rowArray 二維數(shù)組,索引為字段名
*/
public function insert($table,$rowArray)
{
$fields = $values = '';
for (reset($rowArray); $key = key($rowArray);next($rowArray))
{
$fields .= ','.$key; $values .= ',\''.$rowArray[$key].'\'';
}
$this->query('insert into '.$table.'('.substr($fields,1).') values('.substr($values,1).')');
}

/**
* 更新一條記錄
*
* 參數(shù):
* $table 表名
* $rowArray 二維數(shù)組,索引為字段名
* $condition 更新條件
*/
public function update($table,$rowArray,$condition)
{
$fields = '';
for (reset($rowArray);$key = key($rowArray);next($rowArray)) $fields .= ','.$key.'=\''.$rowArray[$key].'\'';
$this->query('update '.$table.' set '.substr($fields,1).' where '.$condition);
}

/**
* 刪除記錄
*
* 參數(shù):
* $table 表明
* $condition 刪除條件,當(dāng)省略時(shí),刪除表中的所有記錄
*/
public function delete($table,$condition = '')
{
$this->query('delete from '.$table.($condition ? ' where '.$condition : ''));
}

/**
* 輸出數(shù)據(jù)列表
*
* 參數(shù):
* $resultId 查詢結(jié)果ID
* $rowHtml 列表的行HTML代碼
* $everyOther 每隔幾行插入$insertHtml
* $insertHtml 需要插入的HTML
*
* $rowHtml的編寫規(guī)則:
* <td>{$name}</td><td>{date('Y-m-d',strtotime($addtime))}</td>
* 需要輸出的字段或用來格式化字段的函數(shù)需用{和}包括
* 變量名使用字段名
*/
public function displayList($resultId,$rowHtml,$everyOther = '',$insertHtml = '')
{
$rowHtml = preg_replace('/\$([A-Za-z0-9_] )/','$rowArray[\'\\1\']',$rowHtml);
$rowHtml = 'echo \''.str_replace(array('{','}'),array('\',',',\''),$rowHtml).'\'';
$i = 1;
while ($rowArray = $this->record($resultId))
{
eval($rowHtml);
if ($everyOther == $i) { echo $insertHtml; $i = 1; }
$i = $i 1;
}
}

/**
* 分頁查詢函數(shù)
*
* 參數(shù):
* $resultId 查詢結(jié)果ID
* $table 所要查詢的數(shù)據(jù)表名
* $fields 需要返回的字段
* $primary 用來排序的字段
* $page 查詢第幾頁
* $pageSize 每頁記錄數(shù)
* $condition 查詢條件,默認(rèn)為空
* $order 排序方式,0為正序,1為倒序,默認(rèn)為1
*
* 說明:
* 此函數(shù)會(huì)將與分頁相關(guān)的信息存儲(chǔ)于$this->pageMsg[$resultId]中
* 這是一個(gè)一維數(shù)組,具有5個(gè)值,分別為:記錄總數(shù),總頁數(shù),當(dāng)前頁記錄數(shù),當(dāng)前第幾頁,每頁多少條記錄
* 可利用這些信息編寫自己的分頁樣式,不需另外計(jì)算
*/
public function limit($resultId,$table,$fields,$primary,$page,$pageSize,$condition = '',$order = 1)
{
isset($this->pageMsg[$resultId][0]) || $this->pageMsg[$resultId][0] = $this->rowsTotal($table,$primary,$condition);
$this->pageMsg[$resultId][1] = ceil($this->pageMsg[$resultId][0]/$pageSize);
$page > $this->pageMsg[$resultId][1] && $page = $this->pageMsg[$resultId][1];
$this->pageMsg[$resultId][2] = $page == $this->pageMsg[$resultId][1] ? ($this->pageMsg[$resultId][0]-($page-1)*$pageSize) : $pageSize;
$this->pageMsg[$resultId][3] = $page;
$this->pageMsg[$resultId][4] = $pageSize;
if ($this->cacheLifeTime && $page <= $this->cacheLimitMax)
{
$cachePath = $this->cachePath.$table.'_'.$page.'.php';
if (time() - @filemtime($cachePath) < $this->cacheLifeTime)
{
include $cachePath; $this->resultId[$resultId] = $dataCache;
$this->offset[$resultId] = 0; return;
} else $writeCache = true;
}
if ($order)
{
$mark = '<'; $min = 'min'; $order = ' order by '.$primary.' desc';
} else {
$mark = '>'; $min = 'max'; $order = '';
}
$sql = 'select top '.$this->pageMsg[$resultId][2].' '.$fields.' from '.$table;
if (1 == $page)
{
$sql .= ($condition ? ' where '.$condition : '').$order;
} else {
$sql .= ' where '.$primary.$mark.'(select '.$min.'('.$primary.') from (select top '.($page-1)*$pageSize;
$sql .= ' '.$primary.' from '.$table.$order.')) '.($condition ? 'and '.$condition : '').$order;
}
$this->query($sql,$resultId);
$writeCache && $this->writeCache($cachePath,$resultId);
}

public function displayLimit($resultId,$linkHtml,$style = 2,$recordName = '條記錄')
{
if (2 == $style)
{
echo '共&nbsp;<strong>',$this->pageMsg[$resultId][0],'</strong>&nbsp;',$recordName,' ';
}
echo '<a href=',str_replace('*','1',$linkHtml),'>首頁</a>&nbsp;';
if (1 == $this->pageMsg[$resultId][3])
{
echo '上一頁&nbsp;';
} else {
echo '<a href=',strtr('*',$this->pageMsg[$resultId][3]-1,$linkHtml),'>上一頁</a>&nbsp;';
}
if ($this->pageMsg[$resultId][3] == $this->pageMsg[$resultId][1])
{
echo '下一頁';
} else {
echo '<a href=',strtr('*',$this->pageMsg[$resultId][3] 1,$linkHtml),'>下一頁</a>';
}
echo '&nbsp;<a href=',strtr('*',$this->pageMsg[$resultId][1],$linkHtml);
echo '>尾頁</a>&nbsp;頁次:<strong><font color=#ff0000>';
echo $this->pageMsg[$resultId][3],'</font>/',$this->pageMsg[$resultId][1],'</strong>頁';
if (2 == $style)
{
echo ' <strong>',$this->pageMsg[$resultId]['e'],'</strong>',$recordName,'/頁&nbsp;轉(zhuǎn)到';
echo ':<select name=page size=1 onchange="javascript:window.location=';
echo 'this.options[this.selectedIndex].value;" style=font-size:12px;height=18px>';
for ($i=1;$i<=$this->pageMsg[$resultId][1];$i )
{
echo '<option value=\'',strtr('*',$i,$linkHtml);
echo $this->pageMsg[$resultId][3] == $i ? '\' selected ' : '\'','>第',$i,'頁</option>';
}
echo '</select>';
}
}

/**
* 將查詢結(jié)果輸入緩存
*
* 參數(shù):
* $cachePath 緩存路徑
* $resultId 查詢結(jié)果ID
*/
private function writeCache($cachePath,$resultId)
{
$cacheContent = '';
while ($rowArray = odbc_fetch_array($this->resultId[$resultId]))
{
$cacheContent .= '$dataCache[]=array('.$this->rowToStr($rowArray).');';
}
file_put_contents($cachePath,'<?php '.$cacheContent.' ?>');
include $cachePath; $this->resultId[$resultId] = $dataCache;
$this->offset[$resultId] = 0;
}

/**
* 將數(shù)組轉(zhuǎn)換為一個(gè)二維數(shù)組結(jié)構(gòu)的字符串
*
* 參數(shù):
* $rowArray 數(shù)組
*/
private function rowToStr($rowArray)
{
for (reset($rowArray);$key = key($rowArray);next($rowArray))
{
$rowStr .= ',\''.$key.'\'=>\''.strtr($rowArray[$key],'\'','\\\'').'\'';
}
return substr($rowStr,1);
}

/**
* 調(diào)用錯(cuò)誤消息頁面,完成錯(cuò)誤消息的顯示
*
* 參數(shù):
* $msg 錯(cuò)誤消息
*/
public function setError($msg)
{
include $this->errPage;
}
}
?>

分享:淺談Access數(shù)據(jù)庫用另一種方式管理密碼
大家都知道,數(shù)據(jù)庫的安全性是很重要的,它直接影響到數(shù)據(jù)庫的廣泛應(yīng)用。用戶可以采用任意一種方法來保護(hù)數(shù)據(jù)庫應(yīng)用程序,也可以將幾種方法結(jié)合起來使用。利用Access數(shù)據(jù)庫自身提供的

共2頁上一頁12下一頁
來源:模板無憂//所屬分類:Access數(shù)據(jù)庫教程/更新時(shí)間:2008-12-02
相關(guān)Access數(shù)據(jù)庫教程