免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2175 | 回复: 0

PHP通过odbc操作ACCESS类 [复制链接]

论坛徽章:
0
发表于 2009-12-07 23:33 |显示全部楼层
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 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  


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/84280/showart_2113431.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP