PHP does not pass the _ PHP Tutorial to test the method of calling the Access database through ADO

Source: Internet
Author: User
Tags mdb database pconnect
The method for calling the Access database through ADO in PHP fails. After reading the article "how to call the Asscess database and COM program through ADO in PHP", I immediately did the test and the result failed. Sad. What should I do? I had to go to the official PHP website and read the article "how to call the Asscess database and COM program in PHP through ADO". then I did the test immediately and the result failed. Sad.

What should I do? I had to go to the official PHP website for help, and Huang Tianyan had no worries, and finally I found the answer --

The specific solution is as follows:
(1) Download the corresponding ZIP package. like MICROSOFT's ADO, this Dongdong uses PHP to implement ADO to deal with a variety of databases (great, all types of databases can handle it ).
(2) unpackage, there are many files in it, but only ohtml is useful. inc. php and adodb. inc. php, (I did not test this) to copy them to the corresponding directory (or the default directory c: \ php4 \ peer \ where php4 is installed, or the Directory of the currently running program, depends on the include () function );
(3) in the c: \ myphp Directory of the local machine (iis is set to be accessed through http: // localhost/jhk), a file named test is created. create an experts table in the access database of mdb ....... In order to ACCESS through DSN, I named the ACCESS library test in DSN.
(4) run. Looking at the instruction book, I made such a program:
Dbtest. php:

The code is as follows:

Include ('tohtml. inc. php'); // load code common to ADODB
Include ('adodb. inc. php'); // load code common to adodb
$ Conn = & ADONewConnection ('access'); // create a connection
$ Conn-> PConnect ('test'); // connect to MySQL, agora db
$ SQL = 'SELECT name, group1 from Experts ';
$ Rs = $ conn-> Execute ($ SQL );
Rs2html ($ rs, 'Border = 2 cellpadding = 3', array ('customer name', 'Customer ID '));
$ Rs-> Close (); // optional
$ Conn-> Close (); // optional
?>



Then, enter http: // localhost/jhk/dbtest. php in IE.
Alas! The result is displayed. Satisfying !!

(5) next, I thought: it's annoying to set up a DSN! How should I solve the problem of bypassing DSN? Because in asp, I used to use conn. open ("provider = Microsoft. jet. OLEDB.4.0; Data Source = "& Server. mappath (".. /nydatabase. mdb ") to process the mdb Database. that's fast!
?...... I thought and thought, and read again .......

Search ,......, Hey, I finally found the answer in testdatabases. inc. php! Then I adapted the program:

The code is as follows:

Include ('tohtml. inc. php'); // load code common to ADODB
Include ('adodb. inc. php'); // load code common to adodb
$ Db = & ADONewConnection ("ado_access ");
Print "Connecting $ db-> databaseType ...";
$ Access = 'Test. mdb ';
$ MyDSN = 'provider = Microsoft. Jet. OLEDB.4.0; '. 'data SOURCE ='. $ access. ';. 'user ID =; PASSWORD = ;';

If (@ $ db-> PConnect ($ myDSN ,"","","")){
Print "ADO version =". $ db-> _ connectionID-> version ."
";
$ SQL = 'SELECT name, group1 from Experts ';
$ Rs = $ db-> Execute ($ SQL );
Rs2html ($ rs, 'Border = 2 cellpadding = 3', array ('customer name', 'Customer ID '));
} Else print "ERROR: Access test requires a Access database $ access ".'
'. $ Db-> ErrorMsg ();
?>




Run.
Everything is done! (The problem cannot be solved after my tests ).

Bytes. Sad. What should I do? I had to go to the official PHP website...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.