$7.49 .com domain with free InstantPage Website Builder$1.99 Web Hosting   捷飞网络官方淘宝店   Godaddy 优惠码
返回列表 发帖
分享到:




[PHP 语言] PHP读取access 数据库的部分方法实例

  1. <?php
  2. //读取mdb数据库例程
  3. $conn = new com("ADODB.Connection");
  4. $connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=". realpath("./SpiderResult.mdb");

  5. $conn->Open($connstr);
  6. $rs = new com("ADODB.RecordSet");
  7. $rs->Open("select * from Content",$conn,1,1);
  8. while(! $rs->eof)
  9. {
  10. echo $rs->Fields(1)->value;
  11. echo "<br>";
  12. echo $rs->Fields(2)->value;
  13. echo "<br>";
  14. echo $rs->Fields(3)->value;
  15. echo "<br>";
  16. echo "<hr>";
  17. $rs->MoveNext();
  18. }
  19. ?>
复制代码
9 [0 ~. g, B, ]

& d; T2 y5 s- w# b1. PHP一般数据读取方法:" g- q: q# e+ M( @& Z+ t- G

3 |/ O+ e, J: F# ~3 A* t- V. `
  1. <?php //读取mdb数据库例程
  2. $conn = new com("ADODB.Connection");
  3. $connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=". realpath("../mydata.mdb");
  4. $conn->Open($connstr);
  5. $rs = new com("ADODB.RecordSet");
  6. $rs->Open("select * from userinfo",$conn,1,1);
  7. while(! $rs->eof) {
  8. $f = $rs->Fields(1);
  9. echo $f->value;
  10. echo "  ". $rs->Fields(2)->value;
  11. $rs->MoveNext();
  12. }
  13. ?>
复制代码

1 _1 M: I( @2 M& j: E3 d! l
  L) A+ y, N0 R' K4 p7 d, Q7 i
% v5 g7 d% g6 k6 u) R9 h2 h: ~( B2. PHP一般数据写入方法:+ ]+ x7 U" _. b! {- @
' v8 M4 s9 i' k& u
" _0 ]- I7 f$ W
  1. <?php
  2. $connstr="DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . realpath("../chen416/mydata.mdb");
  3. $connid=odbc_connect($connstr,"","",SQL_CUR_USE_ODBC);
  4. $issuetime=date("Y-m-d H:i:s");
  5. $sql="insert into userinfo (username,userword,email) values('u2','w2','uw@163.com')";
  6. $result=odbc_exec($connid,$sql);
  7. if($result) echo "successful";
  8. else echo "failed";
  9. ?>
复制代码
5 Z4 J% P& q. I- E

, N, l( m  v9 u7 ?7 k2 M0 ]
1 ~# [7 x# ~7 M* T0 L) u. ~$ B8 A- D3、PHP一般数据读取方法:. \/ a8 t) r) K
) p/ X9 n' K2 E' Z# S% y' D
8 o9 L: t/ h  T* O" v( z# n" k
  1. <?php //读取mdb数据库例程
  2. $conn=new COM("ADODB.Connection");
  3. $dsn="DRIVER={Microsoft Access Driver (*.mdb)};DBQ=".realpath("../mydata.mdb").";";
  4. //Uid=Admin; Pwd=BDC2002Data;
  5. $conn->open($dsn);
  6. $sql="select * from userinfo";
  7. $rs=$conn->Execute($sql);
  8. $row="0";
  9. while(!$rs->EOF)
  10. {
  11. $string ="";
  12. for ($i=0;$i<$rs->Fields->count;$i++)
  13. {
  14. if ($i==0)
  15. {
  16. $string.=$rs->Fields($i)->Value;
  17. continue;
  18. }
  19. $string.='|'.$rs->Fields($i)->Value;
  20. }
  21. $string.="\n";
  22. if ($row==300)
  23. {
  24. break;
  25. }
  26. $row++;
  27. echo "<br>";
  28. echo $string;
  29. $rs->MoveNext();
  30. }
  31. ?>
复制代码
* o; R0 I" F3 O' |/ t- @

( V- t( t" D9 m0 v/ _
( V6 s& }* B& G- _+ M8 V9 P4、PHP删除数据方法:4 K' l: f8 r  G

- n3 O) {+ p' R# U7 `: A7 x$ v
3 ~/ y# ]! G; S7 E
  1. <?php
  2. $conn = new com("ADODB.Connection");
  3. $connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=". realpath("../mydata.mdb");
  4. $conn->Open($connstr);

  5. $query = "delete from userinfo where uid=1";
  6. $result =$conn->Execute($query);

  7. if($result)
  8. echo "删除成功";
  9. else
  10. echo "删除失败";

  11. ?>
复制代码

7 a; {( @/ ]# T7 ]' Z# s% F
4 r2 K% R( ]" Y# h% m/ d8 g7 P, T( S2 Q
* c# _: r6 M  H4 u5、PHP更新数据方法:, I3 M6 j. W1 {. k9 h. ^* s  v

7 [# g3 ?. M  X7 s; ]" s
  1. <?php
  2. $conn = new com("ADODB.Connection");
  3. $connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=". realpath("../mydata.mdb");
  4. $conn->Open($connstr);

  5. $query = "update userinfo set username='ganjun' where uid=2";
  6. $result =$conn->Execute($query);

  7. if($result)
  8. echo "更新数据成功";
  9. else
  10. echo "更新数据失败";

  11. ?>
复制代码
- T' ~5 b; P1 j$ _

% Y5 ]. |7 l! j8 O1 {5 s6 I+ W% V2 p
参考: http://blog.csdn.net/goodnew/article/details/19757485

美国VPS、域名代购:http://tu8l.taobao.com

返回列表
Namecheap
Namecheap.com - Cheap domain name registration, renewal and transfers - Free SSL Certificates - Web Hosting
互联网安全