require_once(dirname(__FILE__)."/../../setting.php"); //加载系统全局常量进来!
include_once(BASEPATH."include/syslog.php"); //加载日志文件
class ODBC_ACCESS {
var $dbpath ;
var $conn;
var $log;
function __construct(){
$this->dbpath = BASEPATH."sysmdb/hnadvs.mdb";
$this->log = new LogsClass();
$this->conn();
}
function conn() {
try {
$connstr="DRIVER=Microsoft Access Driver (*.mdb);DBQ=".@realpath($this->dbpath);
$connid=odbc_connect($connstr,"","",SQL_CUR_USE_ODBC);
$this->conn = $connid;
} catch (Exception $ex) {
$this->log->setLog($ex->getMessage());
}
}
function close_conn() {
odbc_close($this->conn);
}
/*
*
* @author hkebao@126.com
* @see execute SQL commands
* @param SQL:String
**/
function execute_sql($sqls) {
try {
odbc_exec($this->conn,$sqls);
} catch (Exception $ex) {
$this->log->setLog($ex->getMessage());
}
}
/**
* @author hkebao@126.com
* @param SQL:String
* @return array of resultset
* */
function query_sql($sqls) {
try{
$result = odbc_exec($this->conn,$sqls);
print $result;
//$result_array = @odbc_fetch_array($result,2);
$result_array = odbc_fetch_array($result);
echo $result_array;
return $result_array;
}catch (Exception $ex){
echo $ex->getMessage();
}
}
/**
* @author hkebao@126.com
* @return int
* @param $table $condition
* @see $result = $odbcj->countRd("sysadmin","where 1=1");
* so can apply it to check if the record exists
* */
function countRd($table,$condition=""){
$sql = "select count(*) from ". $table." ".$condition;
$query = @odbc_exec($this->conn,$sql);
odbc_fetch_row($query);
$num = odbc_result($query,1);
return $num;
}
/**
* @param SQL:String select * from table where id=1
* @param column:int
* @return array
* @see $result = $odbcj->getInfo("select * from advsinfo where id=2",3); echo $result[2];
* */
function getInfo($sql,$column) {
$query = @odbc_exec($this->conn,$sql);
if (odbc_fetch_row($query)) {
for ($i = 0;$i < $column;$i++) {
$info[$i] = odbc_result($query,$i+1);
}
}
return $info;
}
/**
* @param SQL:String
* @param fieldnum : INT
* @return THE SET OF RESULTSET
* @example
* $result = $odbcj->getList("select * from advsinfo where 1=2",2);
* 2:表示一行取几个字段
* foreach ($result as $val) {
echo $val[1];
}
* */
function getList($sqls,$fieldnum) {
$query = @odbc_exec($this->conn,$sqls);
$i = 0;
while (odbc_fetch_row($query)) {
for ($j=0;$j < $fieldnum;$j++) {
$info[$j] = odbc_result($query,$j+1);
}
$rdList[$i] = $info;
$i++;
}
return $rdList;
}
}
?>
阅读(1066) | 评论(0) | 转发(0) |