在PHP中连接access数据库的话我们必须ADO来连接,这跟ASP中连接数据库非常的类似。下边给出了一段DEMO供大家参考。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | <?PHP /* 创建ADO连接 */ $conn = @ new COM( "ADODB.Connection" ) or die ( "ADO Connection faild." ); $connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . realpath ( "DATUM/cnbt.mdb" ); $conn ->Open( $connstr ); /* 创建记录集查询 */ $rs = @ new COM( "ADODB.RecordSet" ); $rs ->Open( "select * from dbo_dirs" , $conn ,1,3); /* 循环读取数据 */ while (! $rs ->eof){ echo "$rs->Fields[" title"]->Value; echo "<br/>" ; $rs ->Movenext(); //将记录集指针下移 } $rs ->close(); ?> |
No comments:
Post a Comment