I have been studying PHP for the past two days, mainly to cope with some background knowledge required for learning AJAX. I always have an inexplicable closeness to open-source things, money-less things are really amazing. because MYSQL Databases in general space have to spend money separately, I plan to use ACCESS for the time being. The result is that I will be the first to check the information, in the past, PHP performed different operations on different databases ..... so I searched some blogs and found many ACCESS methods, but they were not satisfactory. Finally I found the ADODB. it is a PHP class and has a built-in Operation Method for most of the databases you have ever seen. for example, PHP usually operates on a MYSQL instance like this:
Copy codeThe Code is as follows: $ db = mysql_connect ("localhost", "root", "password ");
Mysql_select_db ("mydb", $ db );
$ Result = mysql_query ("SELECT * FROM employees", $ db );
If ($ result = false) die ("failed ");
While ($ fields = mysql_fetch_row ($ result )){
For ($ I = 0, $ max = sizeof ($ fields); $ I <$ max; $ I ++ ){
Print $ fields [$ I]. '';
}
Print "<br> n ";
}
If ADODB is used, the following program returns the same result.
Copy codeThe Code is as follows: include ("adodb. inc. php ");
$ Db = NewADOConnection ('mysql ');
$ Db-> Connect ("localhost", "root", "password", "mydb ");
$ Result = $ db-> Execute ("SELECT * FROM employees ");
If ($ result = false) die ("failed ");
While (! $ Result-> EOF ){
For ($ I = 0, $ max = $ result-> FieldCount (); $ I <$ max; $ I ++)
Print $ result-> fields [$ I]. '';
$ Result-> MoveNext ();
Print "<br> n ";
}
Then, if you want to use another database, change the connection name of the ADOConnection, and ACCESS will use
$ Db = NewADOConnection ('access ');
The complete code is as follows:
Copy codeThe Code is as follows: <? Php
Include ("adodb/adodb. inc. php ");
$ Db = ADONewConnection ('access ');
$ Dsn = "Driver = {Microsoft Access Driver (*. mdb)}; Dbq = d: \ self \ myphp \ book. mdb; Uid =; Pwd = ;";
$ Db-> Connect ($ dsn );
$ Result = $ db-> Execute ("SELECT * FROM data ");
If ($ result = false) die ("failed ");
While (! $ Result-> EOF ){
For ($ I = 0, $ max = $ result-> FieldCount (); $ I <$ max; $ I ++)
Print "<div style = 'border: 1px solid #000000; '>". $ result-> fields [$ I]. "<br/> ";
$ Result-> MoveNext ();
}
?>
ADODB can download http://phplens.com/phpeverywhere/ here