首頁 > php教程 > php手册 > 主體

PHP通过ADO方式连接Access

WBOY
發布: 2016-06-21 08:52:36
原創
2622 人瀏覽過

PHP通过ADO方式连接Access数据库,如下代码:

<ol class="dp-xml">
<li class="alt"><span><span>nbsp;html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"  </span></span></li>
<li><span>"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"<span class="tag">></span><span> </span></span></li>
<li class="alt"><span><span class="tag"><span class="tag-name">html</span><span> </span><span class="attribute">xmlns</span><span>=</span><span class="attribute-value">"http://www.w3.org/1999/xhtml"</span><span class="tag">></span><span> </span></span></span></li>
<li><span><span class="tag"><span class="tag-name">head</span><span class="tag">></span><span> </span></span></span></li>
<li class="alt"><span><span class="tag"><span class="tag-name">meta</span><span> </span><span class="attribute">http-equiv</span><span>=</span><span class="attribute-value">"Content-Type"</span><span> </span><span class="attribute">content</span><span>=</span><span class="attribute-value">"text/html; charset=gb2312"</span><span> </span><span class="tag">/></span><span> </span></span></span></li>
<li><span><span class="tag"><span class="tag-name">title</span><span class="tag">></span><span>通过ADO方式连接ACCESS数据库 - www.cxybl.com</span><span class="tag"></span><span class="tag-name">title</span><span class="tag">></span><span> </span></span></span></li>
<li class="alt"><span><span class="tag"><span class="tag-name">link</span><span> </span><span class="attribute">rel</span><span>=</span><span class="attribute-value">"stylesheet"</span><span> </span><span class="attribute">type</span><span>=</span><span class="attribute-value">"text/css"</span><span> </span><span class="attribute">href</span><span>=</span><span class="attribute-value">"style.css"</span><span class="tag">></span><span> </span></span></span></li>
<li><span><span class="tag"><span class="tag-name">style</span><span> </span><span class="attribute">type</span><span>=</span><span class="attribute-value">"text/css"</span><span class="tag">></span><span> </span></span></span></li>
<li class="alt"><span><span class="comments"><!--</span> </span></li><li><span><span class="comments">.STYLE1 {color: #FFFFFF}</span> </span></li><li class="alt"><span><span class="comments">--></span><span> </span></span></li>
<li><span><span class="tag"></span><span class="tag-name">style</span><span class="tag">></span><span> </span></span></li>
<li class="alt"><span><span class="tag"></span><span class="tag-name">head</span><span class="tag">></span><span> </span></span></li>
<li><span><span class="tag"></span><span class="tag-name">php</span><span> </span></span></li>
<li class="alt"><span>include_once("conn.php"); </span></li>
<li><span><span class="tag">?></span><span> </span></span></li>
<li class="alt"><span><span class="tag"><span class="tag-name">body</span><span> </span><span class="attribute">topmargin</span><span>=</span><span class="attribute-value">"0"</span><span> </span><span class="attribute">leftmargin</span><span>=</span><span class="attribute-value">"0"</span><span> </span><span class="attribute">bottommargin</span><span>=</span><span class="attribute-value">"0"</span><span class="tag">></span><span> </span></span></span></li>
<li><span><span class="tag"><span class="tag-name">table</span><span> </span><span class="attribute">width</span><span>=</span><span class="attribute-value">"300"</span><span> </span><span class="attribute">border</span><span>=</span><span class="attribute-value">"0"</span><span> </span><span class="attribute">align</span><span>=</span><span class="attribute-value">"center"</span><span> </span><span class="attribute">cellpadding</span><span>=</span><span class="attribute-value">"0"</span><span> </span><span class="attribute">cellspacing</span><span>=</span><span class="attribute-value">"0"</span><span class="tag">></span><span> </span></span></span></li>
<li class="alt"><span>  <span class="tag"><span class="tag-name">tr</span><span class="tag">></span><span> </span></span></span></li>
<li><span>    <span class="tag"><span class="tag-name">td</span><span> </span><span class="attribute">height</span><span>=</span><span class="attribute-value">"25"</span><span> </span><span class="attribute">bgcolor</span><span>=</span><span class="attribute-value">"#0099CC"</span><span class="tag">></span><span class="tag"><span class="tag-name">div</span><span> </span><span class="attribute">align</span><span>=</span><span class="attribute-value">"center"</span><span> </span><span class="attribute">class</span><span>=</span><span class="attribute-value">"STYLE1"</span><span class="tag">></span><span>图书信息</span><span class="tag"></span><span class="tag-name">div</span><span class="tag">></span><span class="tag"></span><span class="tag-name">td</span><span class="tag">></span><span> </span></span></span></span></li>
<li class="alt"><span>  <span class="tag"></span><span class="tag-name">tr</span><span class="tag">></span><span> </span></span></li>
<li><span>  <span class="tag"><span class="tag-name">tr</span><span class="tag">></span><span> </span></span></span></li>
<li class="alt"><span>    <span class="tag"><span class="tag-name">td</span><span> </span><span class="attribute">bgcolor</span><span>=</span><span class="attribute-value">"#0099CC"</span><span class="tag">></span><span class="tag"><span class="tag-name">table</span><span> </span><span class="attribute">width</span><span>=</span><span class="attribute-value">"300"</span><span> </span><span class="attribute">height</span><span>=</span><span class="attribute-value">"50"</span><span> </span><span class="attribute">border</span><span>=</span><span class="attribute-value">"0"</span><span> </span><span class="attribute">align</span><span>=</span><span class="attribute-value">"center"</span><span>  </span></span></span></span></li>
<li><span>    <span class="attribute">cellpadding</span><span>=</span><span class="attribute-value">"0"</span><span> </span><span class="attribute">cellspacing</span><span>=</span><span class="attribute-value">"1"</span><span class="tag">></span><span> </span></span></li>
<li class="alt"><span>      <span class="tag"><span class="tag-name">tr</span><span class="tag">></span><span> </span></span></span></li>
<li><span>        <span class="tag"><span class="tag-name">td</span><span> </span><span class="attribute">width</span><span>=</span><span class="attribute-value">"167"</span><span> </span><span class="attribute">height</span><span>=</span><span class="attribute-value">"25"</span><span> </span><span class="attribute">bgcolor</span><span>=</span><span class="attribute-value">"#FFFFFF"</span><span class="tag">></span><span class="tag"><span class="tag-name">div</span><span> </span><span class="attribute">align</span><span>=</span><span class="attribute-value">"center"</span><span class="tag">></span><span>书名</span><span class="tag"></span><span class="tag-name">div</span><span class="tag">></span><span class="tag"></span><span class="tag-name">td</span><span class="tag">></span><span> </span></span></span></span></li>
<li class="alt"><span>        <span class="tag"><span class="tag-name">td</span><span> </span><span class="attribute">width</span><span>=</span><span class="attribute-value">"130"</span><span> </span><span class="attribute">bgcolor</span><span>=</span><span class="attribute-value">"#FFFFFF"</span><span class="tag">></span><span class="tag"><span class="tag-name">div</span><span> </span><span class="attribute">align</span><span>=</span><span class="attribute-value">"center"</span><span class="tag">></span><span>出版社</span><span class="tag"></span><span class="tag-name">div</span><span class="tag">></span><span class="tag"></span><span class="tag-name">td</span><span class="tag">></span><span> </span></span></span></span></li>
<li><span>      <span class="tag"></span><span class="tag-name">tr</span><span class="tag">></span><span> </span></span></li>
<li class="alt"><span>      <span class="tag"></span><span class="tag-name">php</span><span> </span></span></li>
<li><span>       $<span class="attribute">sql</span><span>=</span><span class="attribute-value">"select * from tb_book"</span><span>; </span></span></li>
<li class="alt"><span>       $<span class="attribute">rs</span><span>=</span><span class="attribute-value">new</span><span> com("adodb.recordset"); </span></span></li>
<li><span>       $rs-<span class="tag">></span><span>open($sql,$conn,1,3); </span></span></li>
<li class="alt"><span>       while(!$rs-<span class="tag">></span><span>eof) </span></span></li>
<li><span>       { </span></li>
<li class="alt"><span>      <span class="tag">?></span><span> </span></span></li>
<li><span>      <span class="tag"><span class="tag-name">tr</span><span class="tag">></span><span> </span></span></span></li>
<li class="alt"><span>        <span class="tag"><span class="tag-name">td</span><span> </span><span class="attribute">height</span><span>=</span><span class="attribute-value">"25"</span><span> </span><span class="attribute">bgcolor</span><span>=</span><span class="attribute-value">"#FFFFFF"</span><span class="tag">></span><span class="tag"><span class="tag-name">div</span><span> </span><span class="attribute">align</span><span>=</span><span class="attribute-value">"center"</span><span class="tag">></span><span> </span></span></span></span></li>
<li><span>      <span class="tag"></span><span class="tag-name">php</span><span> $</span><span class="attribute">fields</span><span>=$rs-</span><span class="tag">></span><span>fields(bookname);echo $fields-</span><span class="tag">></span><span>value;</span><span class="tag">?></span><span class="tag"></span><span class="tag-name">div</span><span class="tag">></span><span class="tag"></span><span class="tag-name">td</span><span class="tag">></span><span> </span></span></li>
<li class="alt"><span>        <span class="tag"><span class="tag-name">td</span><span> </span><span class="attribute">height</span><span>=</span><span class="attribute-value">"25"</span><span> </span><span class="attribute">bgcolor</span><span>=</span><span class="attribute-value">"#FFFFFF"</span><span class="tag">></span><span class="tag"><span class="tag-name">div</span><span> </span><span class="attribute">align</span><span>=</span><span class="attribute-value">"center"</span><span class="tag">></span><span> </span></span></span></span></li>
<li><span>      <span class="tag"></span><span class="tag-name">php</span><span> $</span><span class="attribute">fields</span><span>=$rs-</span><span class="tag">></span><span>fields(pub);echo $fields-</span><span class="tag">></span><span>value;</span><span class="tag">?></span><span class="tag"></span><span class="tag-name">div</span><span class="tag">></span><span class="tag"></span><span class="tag-name">td</span><span class="tag">></span><span> </span></span></li>
<li class="alt"><span>      <span class="tag"></span><span class="tag-name">tr</span><span class="tag">></span><span> </span></span></li>
<li><span>      <span class="tag"></span><span class="tag-name">php</span><span> </span></span></li>
<li class="alt"><span>         $rs-<span class="tag">></span><span>movenext; </span></span></li>
<li><span>       } </span></li>
<li class="alt"><span>      <span class="tag">?></span><span> </span></span></li>
<li><span>    <span class="tag"></span><span class="tag-name">table</span><span class="tag">></span><span class="tag"></span><span class="tag-name">td</span><span class="tag">></span><span> </span></span></li>
<li class="alt"><span>  <span class="tag"></span><span class="tag-name">tr</span><span class="tag">></span><span> </span></span></li>
<li><span><span class="tag"></span><span class="tag-name">table</span><span class="tag">></span><span> </span></span></li>
<li class="alt"><span><span class="tag"></span><span class="tag-name">body</span><span class="tag">></span><span> </span></span></li>
<li><span><span class="tag"></span><span class="tag-name">html</span><span class="tag">></span><span> </span></span></li>
</ol>
登入後複製

conn.php:

<ol class="dp-c">
<li class="alt"><span><span><?php  </span></span></span></li>
<li><span><span class="vars">$conn</span><span> = </span><span class="keyword">new</span><span> com(</span><span class="string">"adodb.connection"</span><span>);   </span></span></li>
<li class="alt"><span><span class="vars">$connstr</span><span>=</span><span class="string">"driver={microsoft access driver (*.mdb)}; dbq="</span><span>. </span><span class="func">realpath</span><span>(</span><span class="string">"data/db_database12_185.mdb"</span><span>); </span></span></li>
<li><span><span class="vars">$conn</span><span>->open(</span><span class="vars">$connstr</span><span>); </span></span></li>
<li class="alt"><span>?> </span></li>
</ol>
登入後複製



相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門推薦
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板