ADODB簡介以及簡單使用

來源:互聯網
上載者:User
1、adodb資料庫類介紹
雖然 PHP 是建構 Web 系統強有力的工具,但是 PHP 存取資料庫的功能,一直未能標準化,每一種資料庫,都使用另一種不同且不相容的應用程式介面(API)。為了填補這個缺憾,因此才有 ADODB 的出現。一旦存取資料庫的介面予以標準化,就能隱藏各種資料庫的差異,若欲轉換至其它不同的資料庫,將變得十分容易 使用 ADODB 最大的優點之一是:不管後端資料庫如何,存取資料庫的方式都是一致的,開發設計人員不必為了某一套資料庫,而必須再學習另一套不同的存取方法,這大大減輕開發人員的知識負擔,過去的知識往後仍可繼續使用,轉移資料庫平台時,程式碼也不必做太大的更動。
二、 簡單的使用
<form action="" method="post"> 使用者名稱:<input name="username" value="" type="text" /> 密碼:<input name="password" value="" type="text" /> <br /> <input name="sub" value="提交" type="submit" /> </form> <?php include("adodb5/adodb.inc.php"); $db=NewADOConnection("mysql");//串連mysql,如果要用access $db->Connect("localhost","root","","ceshiphp") or die("串連資料庫出錯");   //串連資料庫參數:伺服器,使用者,密碼,資料庫 $db->Execute("set names 'utf8'");//執行編碼 $query=$db->Execute("select * from `think_user`"); /*while($row=$query->FetchRow())//讀取內容 {  print_r($row); }*/ //自動插入內容 if(isset($_POST['sub'])){ $arr=array("user"=>"張三",               "password"=>"123"  );    //  對於插入  多餘的無法插入 $db->AutoExecute("think_user",$arr,"INSERT"); } ?>

include("adodb5/adodb.inc.php");  
/* $db=NewADOConnection("mysql://root:@localhost/ceshiphp"); $sql="select * from think_user"; $db->SetFetchMode(ADODB_FETCH_ASSOC);    //或者使用ADODB_FETCH_NUM $sr1=$db->Execute($sql); print_r($sr1->fields); */   /*   $db=NewADOConnection("mysql");//串連mysql,如果要用access   $db->Connect("localhost","root","","ceshiphp") or die("串連資料庫出錯");   //串連資料庫參數:伺服器,使用者,密碼,資料庫   $db->Execute("set names 'utf8'");//執行編碼   $sql="select * from think_user";   $sr2=$db->Execute($sql);     //  這裡使用的是讀取之後返回對象    while($row=$sr2->FetchNextObject())   {    print_r($row);    //echo $row->UID;   } */          //下面的例子是按照html格式輸出資料庫內容 /*   include("adodb5/tohtml.inc.php");   $db=NewADOConnection("mysql");//串連mysql,如果要用access   $db->Connect("localhost","root","","ceshiphp") or die("串連資料庫出錯");   //串連資料庫參數:伺服器,使用者,密碼,資料庫   $db->Execute("set names 'utf8'");//執行編碼   $sql="select * from think_user";   $sr2=$db->Execute($sql);   //print_r($sr2);   echo rs2html($sr2);  */           //下面是adodb內建的翻頁   include("adodb5/adodb-pager.inc.php");   session_start();   $db=NewADOConnection("mysql");//串連mysql,如果要用access   $db->Connect("localhost","root","","ceshiphp") or die("串連資料庫出錯");   //串連資料庫參數:伺服器,使用者,密碼,資料庫   $db->Execute("set names 'utf8'");//執行編碼   $sql="select * from think_user";       $pager=new ADODB_Pager($db,$sql);   $pager->Render(2);//每頁顯示多少條數
?>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.