The method for calling the Access database through ADO in PHP fails to be tested.

Source: Internet
Author: User
Tags mdb database pconnect php website
In PHP, the method for calling the Access database through ADO does not pass the test. I read the article "how to call the Asscess database and COM program through ADO in PHP" and immediately tested it, 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 ).

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.