Home  >  Article  >  Backend Development  >  PHP connect access database_PHP tutorial

PHP connect access database_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 09:59:46814browse

PHP connects to the access database

This article introduces you to an example of how to use ADO to link to the ACCESS database in PHP. It is very simple to use and is recommended to those in need. Friends, please refer to it.

Because the PingSwitch I made before was to be a front-end for WEB display, because the structure of Delphi and access was used at the beginning, and the connection between Delphi and MySQL was relatively troublesome, in the end I could only choose to use the combination of PHP Access, which is quite strange. But it’s reasonable...

To connect to the access database in PHP, we must use ADO to connect, which is very similar to connecting to the database in ASP. A DEMO is given below for your reference.

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

/*

创建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 "
";

$rs->Movenext(); //将记录集指针下移

}

$rs->close();

?>

1 2

3

4

5 6

78 9 10 11 12 13
14
15
16 17 18 19 20 21 22
<🎜>/*<🎜> <🎜>Create ADO connection<🎜> <🎜>*/<🎜> <🎜>$conn = @new COM("ADODB.Connection") or die ("ADO Connection failed.");<🎜> <🎜>$connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . realpath("DATUM/cnbt.mdb");<🎜> <🎜>$conn->Open($connstr); /* Create recordset query */ $rs = @new COM("ADODB.RecordSet"); $rs->Open("select * from dbo_dirs",$conn,1,3); /* Loop to read data */ while(!$rs->eof){ echo "$rs->Fields["title"]->Value; echo "
"; $rs->Movenext(); //Move the record set pointer down } $rs->close(); ?>
There will be no problem running this way... The above is the entire content of this article, I hope you all like it. http://www.bkjia.com/PHPjc/975133.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/975133.htmlTechArticlePHP connection access database This article introduces to you an example of using ADO to link the ACCESS database in php. It is very simple to use. I recommend it to friends who need it for reference...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn