Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Database (Microsoft)

How do I connect to an Access(mdb) database? by Karl Blessing
Posted: 14 Jun 01

This quick tutorial by example, assumes that you have PHP setup on a Windows2000 or NT machine using IIS4+

A quick example by source on how, to demostrate how, I wrote a little quick PHP version of the new postings on my site, (most of my site is done in ASP, I myself am just learning some PHP , I like the structure)

<BODY bgcolor=#FFFFFF>
<Table border=1 width="100%" bgcolor="darkgray" cellpadding=0 cellspacing=0>
$conn = new COM("ADODB.Connection") or die("Cannot start ADO");
//creates the connection object
$conn->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\wwwRoot\\kb244com\\www\\_private\\database\\SiteDb2k.mdb;Mode=ReadWrite;Persist Security Info=False");
//opens a connection using a connection string, for some
//people "DSN=name" will suffice if you are using a dNS connection
$rs = $conn->Execute("Select * from Postings order by PostDate DESC");
//opens a recordset from the connection object
    while (!$rs->EOF) {
    //keep looping until end of file
    <? $fv = $rs->Fields("PostDate"); ?>
        //in ASP the date comes back correctly for a
        // Date/time type, not sure why it comes back different
        // in PHP
    <TD width="20%" align=left bgcolor=#B5BED6 nowrap><b><? echo $fv->value; ?></b></TD>
    <? $fv = $rs->Fields("PostTopic"); ?>
    <TD align=center bgcolor=#B5BED6><i><? echo $fv->value; ?></i></TD>
    <TD colspan=2 align=left bgcolor="lightgrey">
    <? $fv = $rs->Fields("Post"); ?>
    echo ereg_replace( "\n", "<br>", $fv->value );
    <? $fv = $rs->Fields("Signature"); ?>
    <TD colspan=2 align=right bgcolor=#B5BED6><? echo $fv->value; ?></TD>
    <td colspan=2>รก</td>

there you have it a simple connection to an Access database, just make sure that if the database is stored locally on the web, you must put it in a folder with write permision so that it can create it's temporary files.

It is also advisible to place it in the _private folder, so that global webvieiwers cant just download the database (any other folder and the person only needs to do http://www.kb244.com/thefile.mdb to get your database)

Also if anyone of you have ideas on how to improve upon this, let me know, as it would benefit me.

Back to PHP FAQ Index
Back to PHP Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close