The method of using ADODB to allow PHP to operate the ACCESS database has been studied in PHP for the past two days, mainly to cope with the background knowledge needed to learn AJAX, I have always had an inexplicable sense of closeness to open-source things, and don't want to pay for things. this is really amazing. because MYSQL databases in general space have to spend money separately, I plan to use ACCESS for the time being, the results show that the data is too big. PHP has 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:
The 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"
N ";
}
If ADODB is used, the following program returns the same result.
The 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"
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:
The code is as follows:
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"
". $ Result-> fields [$ I]."
";
$ Result-> MoveNext ();
}
?>
ADODB can download http://phplens.com/phpeverywhere/ href = "http://phplens.com/phpeverywhere/" target = _ blank> http://phplens.com/phpeverywhere/ here