php編寫的ACCESS處理類

來源:互聯網
上載者:User

    在做項目中要用到ACCESS資料庫,所以就寫了一個ACCESS處理類.函數名跟ADODB類一樣.

 



<?php
/*
*ACCESS資料庫操作類
*2008-3-26
*LIQUAN
*$dsn = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=".PATH_ROOT."databasedata.mdb";
*$conn=new Access();
*$conn->Connnect($dsn);
*$conn->GetArray("select * from test");
*/

class Access
{
    var $conn;
    var $fieldsName;
    
    function Access()
    {
   
    }

    //connection 
    function Connect($dsn)
    {
        $this->conn = new COM("ADODB.Connection") or die("Cannot start ADO");
        $this->conn->Open($dsn);
    }

    //返回一個
    function GetOne($sql)
    {  
       $rs = $this->conn->Execute($sql);
       while (!$rs->EOF)
       {
             $value=$rs->Fields(0)->value;      
          $rs->MoveNext();
       }
        $rs->Close();
        $rs=null;

        if(!empty($value))
        {
          return  $value;
        }
        else
        {
          return "";
        }
        unset($value);
    }


   //返回大數組
    function GetArray($sql)
    {
      
       $rs = $this->conn->Execute($sql);
       $num_columns = $rs->Fields->Count();
        $rowcount = 0;
        while (!$rs->EOF)
        {
          for ($i=0; $i < $num_columns; $i++)
          {
                   $fieldName[$rowcount][$rs->Fields($i)->name]= $rs->Fields($i)->value;
          }
          $rowcount++;            
          $rs->MoveNext();
        }
        $rs->Close();

        $rs=null;
        if(!empty($fieldName))
        {
          return  $fieldName;
        }
        else
        {
          return "";
        }
        
        unset($fieldName);
    }

    //返回小數組
    function GetRow($sql)
    {
       $rs = $this->conn->Execute($sql);
       $num_columns = $rs->Fields->Count();
        
       while (!$rs->EOF)
       {
          for ($i=0; $i < $num_columns; $i++)
          {
                  $fieldName[$rs->Fields($i)->name]=$rs->Fields($i)->value;
          }      

          $rs->MoveNext();
        }
        $rs->Close();

        $rs=null;
        if(!empty($fieldName))
        {
          return  $fieldName;
        }
        else
        {
          return "";
        }
       unset($fieldName);

    }

    //execute SQL
    function Execute($sql)
    {
       if($this->conn->Execute($sql))
       {
         return true;
       }
       else
       {
         return false;
       }
    }

    function Close()
    {
        $this->conn->Close();
    }

     function __destruct()
     {
      // $this->conn->Close();
     }



}

?>

 

 



</

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.