欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

PHP通过ADO方式连接Access

程序员文章站 2022-04-11 18:06:24
...
PHP通过ADO方式连接Access数据库,如下代码:
  1. /span>
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. html xmlns="http://www.w3.org/1999/xhtml">
  4. head>
  5. meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
  6. title>通过ADO方式连接ACCESS数据库 - www.cxybl.comtitle>
  7. link rel="stylesheet" type="text/css" href="style.css">
  8. style type="text/css">
  9. style>
  10. head>
  11. php
  12. include_once("conn.php");
  13. ?>
  14. body topmargin="0" leftmargin="0" bottommargin="0">
  15. table width="300" border="0" align="center" cellpadding="0" cellspacing="0">
  16. tr>
  17. td height="25" bgcolor="#0099CC">div align="center" class="STYLE1">图书信息div>td>
  18. tr>
  19. tr>
  20. td bgcolor="#0099CC">table width="300" height="50" border="0" align="center"
  21. cellpadding="0" cellspacing="1">
  22. tr>
  23. td width="167" height="25" bgcolor="#FFFFFF">div align="center">书名div>td>
  24. td width="130" bgcolor="#FFFFFF">div align="center">出版社div>td>
  25. tr>
  26. php
  27. $sql="select * from tb_book";
  28. $rs=new com("adodb.recordset");
  29. $rs->open($sql,$conn,1,3);
  30. while(!$rs->eof)
  31. {
  32. ?>
  33. tr>
  34. td height="25" bgcolor="#FFFFFF">div align="center">
  35. php $fields=$rs->fields(bookname);echo $fields->value;?>div>td>
  36. td height="25" bgcolor="#FFFFFF">div align="center">
  37. php $fields=$rs->fields(pub);echo $fields->value;?>div>td>
  38. tr>
  39. php
  40. $rs->movenext;
  41. }
  42. ?>
  43. table>td>
  44. tr>
  45. table>
  46. body>
  47. html>

conn.php:

  1. $conn = new com("adodb.connection");
  2. $connstr="driver={microsoft access driver (*.mdb)}; dbq=". realpath("data/db_database12_185.mdb");
  3. $conn->open($connstr);
  4. ?>