#1 253618
把以下代码加入到pdo.php使用access时,添加及更新数据时,由于access无法字段列表,只能用原生的SQL/**
* db_pdo_odbc PDO mdb数据驱动类
*/
class db_pdo_odbc extends db_pdo {
/**
* 返回当前插入记录的主键ID
*/
public function newinsertid(){
$result = $this->getArray("select @@IDENTITY as sptmp_newinsert_id");
return $result[0]['sptmp_newinsert_id'];
}
//limit数据查询函数
function translimit($sql, $count, $offset = 0) {
$count = intval($count);
if ($count <= 0) {
}
$offset = intval($offset);
if ($offset < 0) {
}
$orderby = stristr($sql, 'ORDER BY');
if ($orderby !== false) {
$sort = (stripos($orderby, 'desc') !== false) ? 'desc' : 'asc';
$order = str_ireplace('ORDER BY', '', $orderby);
$order = trim(preg_replace('/ASC|DESC/i', '', $order));
}
$sql = preg_replace('/^SELECT\s/i', 'SELECT TOP ' . ($count + $offset) . ' ', $sql);
$sql = 'SELECT * FROM (SELECT TOP ' . $count . ' * FROM (' . $sql . ') AS inner_T';
if ($orderby !== false) {
$sql .= ' ORDER BY ' . $order . ' ';
$sql .= (stripos($sort, 'asc') !== false) ? 'DESC' : 'ASC';
}
$sql .= ') AS outer_T';
if ($orderby !== false) {
$sql .= ' ORDER BY ' . $order . ' ' . $sort;
}
return $sql;
}
/**
* 格式化带limit的SQL语句
*/
public function setlimit($sql, $limit){
if(!eregi(",", $limit))$limit = '0,'.$limit;
$limit = explode(',',$limit);
//$sql .= " LIMIT {$limit}";
$offset = $limit[0];
$count = $limit[1];
return $this->translimit($sql,$count,$offset);
}
}
2011-05-26 12:49:17