php的access操作类


Posted in PHP onApril 09, 2008
<?php     
--------------------------------------------------------------------     
//FileName:class.php     
//Summary: Access数据库操作类     
//Author:  forest     
//CreateTime: 2006-8-10          
//LastModifed:     
//copyright (c)2006      
//http://freeweb.nyist.net/~chairy       
//[email]chaizuxue@163.com[/email]     
//   使用范例:     
//$databasepath="database.mdb";     
//$dbusername="";     
//$dbpassword="";     
//include_once("class.php");     
//$access=new Access($databasepath,$dbusername,$dbpassword);     --------------------------------------------------------------------     
    class Access     
    {     
         var $databasepath,$constr,$dbusername,$dbpassword,$link;     
         function Access($databasepath,$dbusername,$dbpassword)     
         {     
               $this->databasepath=$databasepath;     
        $this->username=$dbusername;     
        $this->password=$dbpassword;     
        $this->connect();     
          }     
    function connect()     
    {     
        $this->constr="DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . realpath($this->databasepath);      
        $this->link=odbc_connect($this->constr,$this->username,$this->password,SQL_CUR_USE_ODBC);     
        return $this->link;     
        //if($this->link) echo "恭喜你,数据库连接成功!";     
        //else echo "数据库连接失败!";     
    }     
    function query($sql)     
    {     
        return @odbc_exec($this->link,$sql);     
    }     
    function first_array($sql)     
    {     
        return odbc_fetch_array($this->query($sql));     
    }     
    function fetch_row($query)     
    {     
        return odbc_fetch_row($query);     
    }     
    function total_num($sql)//取得记录总数     
    {     
        return odbc_num_rows($this->query($sql));     
    }     
    function close()//关闭数据库连接函数     
    {         
        odbc_close($this->link);     
    }     
    function insert($table,$field)//插入记录函数     
    {     
        $temp=explode(',',$field);     
        $ins='';     
        for ($i=0;$i<count($temp);$i++)     
        {     
            $ins.="'".$_POST[$temp[$i]]."',";     
        }     
        $ins=substr($ins,0,-1);     
        $sql="INSERT INTO ".$table." (".$field.") VALUES (".$ins.")";     
        $this->query($sql);     
    }     
    function getinfo($table,$field,$id,$colnum)//取得当条记录详细信息     
    {     
        $sql="SELECT * FROM ".$table." WHERE ".$field."=".$id."";     
        $query=$this->query($sql);     
        if($this->fetch_row($query))     
        {     
            for ($i=1;$i<$colnum;$i++)     
            {     
          $info[$i]=odbc_result($query,$i);     
             }     
         }     
         return $info;     
    }     
    function getlist($table,$field,$colnum,$condition,$sort="ORDER BY id DESC")//取得记录列表         
    {     
         $sql="SELECT * FROM ".$table." ".$condition." ".$sort;     
         $query=$this->query($sql);     
         $i=0;     
         while ($this->fetch_row($query))      
         {     
        $recordlist[$i]=getinfo($table,$field,odbc_result($query,1),$colnum);     
        $i++;     
          }     
          return $recordlist;     
    }     
    function getfieldlist($table,$field,$fieldnum,$condition="",$sort="")//取得记录列表     
    {     
         $sql="SELECT ".$field." FROM ".$table." ".$condition." ".$sort;     
         $query=$this->query($sql);     
         $i=0;     
         while ($this->fetch_row($query))      
         {     
         for ($j=0;$j<$fieldnum;$j++)     
        {     
                   $info[$j]=odbc_result($query,$j+1);     
        }         
        $rdlist[$i]=$info;     
        $i++;     
         }     
         return $rdlist;     
    }     
    function updateinfo($table,$field,$id,$set)//更新记录     
    {     
        $sql="UPDATE ".$table." SET ".$set." WHERE ".$field."=".$id;     
        $this->query($sql);     
    }     
    function deleteinfo($table,$field,$id)//删除记录     
    {     
         $sql="DELETE FROM ".$table." WHERE ".$field."=".$id;     
         $this->query($sql);     
    }     
    function deleterecord($table,$condition)//删除指定条件的记录     
    {     
         $sql="DELETE FROM ".$table." WHERE ".$condition;     
         $this->query($sql);     
    }     
    function getcondrecord($table,$condition="")// 取得指定条件的记录数     
    {     
         $sql="SELECT COUNT(*) AS num FROM ".$table." ".$condition;     
         $query=$this->query($sql);     
         $this->fetch_row($query);     
         $num=odbc_result($query,1);     
         return $num;                 
    }     
     }     
?> 
PHP 相关文章推荐
PHP小程序自动提交到自助友情连接
Nov 24 PHP
PHP Zip解压 文件在线解压缩的函数代码
May 26 PHP
ThinkPHP自动验证失败的解决方法
Jun 09 PHP
解析php中curl_multi的应用
Jul 17 PHP
PHP中数组定义的几种方法
Sep 01 PHP
dedecms集成财付通支付接口
Dec 28 PHP
php 升级到 5.3+ 后出现的一些错误,如 ereg(); ereg_replace(); 函数报错
Dec 07 PHP
PHP实现将base64编码字符串转换成图片示例
Jun 22 PHP
PHP使用PDO创建MySQL数据库、表及插入多条数据操作示例
May 30 PHP
Yii 使用intervention/image拓展实现图像处理功能
Jun 22 PHP
JS操作XML中DTD介绍及使用方法分析
Jul 04 PHP
tp5修改(实现即点即改)
Oct 18 PHP
php时间不正确的解决方法
Apr 09 #PHP
php Ajax乱码
Apr 09 #PHP
PHP提取中文首字母
Apr 09 #PHP
php出现Cannot modify header information问题的解决方法大全
Apr 09 #PHP
php md5下16位和32位的实现代码
Apr 09 #PHP
用来给图片加水印的PHP类
Apr 09 #PHP
在PHP中读取和写入WORD文档的代码
Apr 09 #PHP
You might like
不用数据库的多用户文件自由上传投票系统(3)
2006/10/09 PHP
php 无极分类(递归)实现代码
2010/01/05 PHP
apache php模块整合操作指南
2012/11/16 PHP
thinkphp循环结构用法实例
2014/11/24 PHP
php实现俄罗斯乘法实例
2015/03/07 PHP
Docker 如何布置PHP开发环境
2016/06/21 PHP
jQuery前台数据获取实现代码
2011/03/16 Javascript
javascript中自定义对象的属性方法分享
2013/07/12 Javascript
js 去掉空格实例 Trim() LTrim() RTrim()
2014/01/07 Javascript
js鼠标滑轮滚动事件绑定的简单实例(兼容主流浏览器)
2014/01/14 Javascript
js函数参数设置默认值的一种变通实现方法
2014/05/26 Javascript
JavaScript继承学习笔记【新手必看】
2016/05/10 Javascript
JavaScript实现图片无缝滚动效果
2017/07/07 Javascript
js实现带进度条提示的多视频上传功能
2020/12/13 Javascript
解决vue单页使用keep-alive页面返回不刷新的问题
2018/03/13 Javascript
Vue实现6位数密码效果
2018/08/18 Javascript
vue+springboot实现项目的CORS跨域请求
2018/09/05 Javascript
JS/CSS实现字符串单词首字母大写功能
2019/09/03 Javascript
vue+element使用动态加载路由方式实现三级菜单页面显示的操作
2020/08/04 Javascript
Vue如何实现变量表达式选择器
2021/02/18 Vue.js
Unicode和Python的中文处理
2017/03/19 Python
Python中低维数组填充高维数组的实现
2019/12/02 Python
Python中包的用法及安装
2020/02/11 Python
如何快速理解python的垃圾回收机制
2020/09/01 Python
Python 列表反转显示的四种方法
2020/11/16 Python
利用纯html5绘制出来的一款非常漂亮的时钟
2015/01/04 HTML / CSS
TALLY WEiJL法国网上商店:服装、时装及配饰
2019/08/31 全球购物
亚洲在线旅行门户网站:Expedia.com.hk(智游网)
2020/04/14 全球购物
物理专业本科生自荐信
2014/01/30 职场文书
财务总监岗位职责
2014/03/07 职场文书
节约用水倡议书
2014/04/16 职场文书
学校办公室主任岗位职责
2015/04/01 职场文书
推普标语口号大全
2015/12/26 职场文书
基于PyQt5制作一个群发邮件工具
2022/04/08 Python
Golang获取List列表元素的四种方式
2022/04/20 Golang
如何vue使用el-table遍历循环表头和表体数据
2022/04/26 Vue.js