> php教程 > php手册 > PHP通过ADO方式连接Access

PHP通过ADO方式连接Access

WBOY
풀어 주다: 2016-06-21 08:52:36
원래의
2624명이 탐색했습니다.

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으로 문의하세요.
인기 추천
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿