国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > PHP > 正文

php操作access數據庫類代碼

2024-07-21 02:13:52
字體:
來源:轉載
供稿:網友


收集最實用的網頁特效代碼!

以下是引用片段:
以下為引用的內容:
<?php
    class access//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)//從access數據庫中返回一個數組
        {
            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;            
        }
    }
?> 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 林周县| 平陆县| 池州市| 漠河县| 南昌市| 建瓯市| 唐山市| 芦溪县| 上蔡县| 楚雄市| 武川县| 沙河市| 荆门市| 乌兰浩特市| 锦州市| 台东县| 灌云县| 密山市| SHOW| 黔江区| 仪征市| 达孜县| 朝阳市| 全南县| 杂多县| 景谷| 和林格尔县| 赤城县| 江山市| 牙克石市| 望城县| 兴宁市| 吉安县| 乡宁县| 庆阳市| 平原县| 阳曲县| 海原县| 英吉沙县| 平潭县| 平潭县|