Not so long ago developers would have said that it is near impossible to use an open source programming language with a Microsoft Access database. But these days it is possible. Thanks to ODBC. Open DataBase Connectivity(ODBC) is an Application Programming Interface (API) that allows a programmer to abstract a program from a particular database type or technology. What this means is that you do not have to write separate code for every type of database that you wanted to interact with. All that you do is to write code that uses the ODBC API and it will be sufficient to communicate with as many different databases as needed. In this article we will create a guestbook with a MS Access database backend.
This article assumes that the reader has installed all of the above applications and has at least some basic programming knowledge of PHP.
Start up MS Access and create a new database called guestbook. Then create a table called comments. Add the following fields to the comments table:
The next thing we need to do is to create an ODBC connection to our Access database. With an ODBC connection, you can connect to any database, on any computer in your network, as long as an ODBC connection is available.
Here is how to create an ODBC connection to a MS Access Database:
Tip: This configuration has to be done on the computer where your web site is located. If you are running Internet Information Server (IIS) on your own computer, the instructions above will work, but if your web site is located on a remote server, you have to have physical access to that server, or ask your web host to set up a DSN for you to use.
Now, let’s retrieve the data from the database using the newly created connection with PHP. Here’s the code:
And here’s the outcome of the above code: