Invoke Access database via ADO in PHP

Source: Internet
Author: User
Tags array dsn include pconnect php and php website access database
access|ado| Data | Database I read the article "How to invoke Asscess database and COM program in PHP" after the article, the test immediately, the result failed. Sad isn't it.

What to do? I had to go to the official PHP website for help, emperor not negative, finally I found the answer--

The specific solution is as follows:
(1) Enter the Http://php.weblogs.com/adodb, download the corresponding zip package; like Microsoft's ADO, it uses PHP to implement ADO to deal with a variety of databases (great, all types of databases can handle).

(2) Unpack, there are a lot of files, but only useful ohtml.inc.php and adodb.inc.php, copy them to the appropriate directory (or install PHP4 under the default directory C:\php4\peer\, or the current running program directory, depending on include () function);

(3) Then in the c:\myphp directory of the chicken (the wrong word one, is the machine) (IIS set up through the HTTP://LOCALHOST/JHK to access), built a access library called Test.mdb, inside to recreate a experts table ... To access it through DSN, I named Test in the DSN for the Access library I just had.

(4) run. Looking at the instructions, I built this program:
dbtest.php, the contents are as follows:
<?php
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, in IE, enter: http://localhost/jhk/dbtest.php
Alas! The result came out. Basic Satisfaction!!

(5) Then, I think: also to set DSN, annoying not annoying! How do I solve a DSN bypass? Because in ASP, I am accustomed to use Conn.Open ("Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & Server.MapPath (". /nydatabase.mdb ") to handle the MDB library, that's fast!

? ...... Think and think, look and see ...

Look for, ..., hey, finally found the answer in testdatabases.inc.php! I'm going to adapt the procedure just now:
<?php
Include (' tohtml.inc.php '); Load code common to ADODB
Include (' adodb.inc.php '); Load code common to ADODB
$db = &adonewconnection ("ado_access");
Print "$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. " <br> ";
$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. ' <BR> $db->errormsg ();
?>

Run.
Everything's done!


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.