![]() Join Up! 96815 members and counting! |
|
|||
Interfacing With MS Access 97+
Siddharth Venkatesan
Before commencing this tutorial, i have to say that for the ODBC setup section,
I used the work
of Leo West. His page
on ODBC setup and interfacing with Ms-SQL server was most usefull to my original work project...
Until my boss changed the project specs to make the database to be MS-Access, instead of MySQL.
If you need to find out more information about SQL, go
here. Summary of Contents
I am going to assume a *little* experience in databases. Having said that, I'm
really only hoping that you know how to create a database and insert tables
into that database.
Requirements
Files used in this tutorial (remove .sid extension to make functional)
I have given directions on exactly how to make the above files. But just in case
my directions aren't 100% correct, you can download a working copy of the relevant
software.
Important Notes
Throughout this tutorial, i have assumed that the person who will interface with
the database will have full read and write priveleges to the database. It is best
in any circumstance to make sure you have read and write priveleges to the
database. Having said that, please, please, please try out these techniques on a
sample database located on a 'local' machine. I know first hand the trouble caused
if you screw up a company database upon which most of the company relies.
So, it's onto the tutorial.
Creating An Access Database To Use
Generally when you start up access, it gives you the option of opening an
existing database or creating a new one.
For the purpose of this tutorial, im going to assume you are going to create a
new database.
Start up Access. If Access is already running, close all other Access
databases currently open. This is just to make the tutorial a bit easier.
Now, create a new Access Database. You can call this database whatever you like.
Just make sure you remember the name and the location you save it to, as you will need
it later to create the ODBC connection. Into this database create the table 'People'.
Into people, add the fields of name and specific types as follows:
You dont need to populate the table as we will do that later on.
Setting Up The ODBC Connection
I previously mentioned Leo West and its from this page that I found out how to
create an ODBC link. To create an ODBC link, open up Control Panel and
from within control panel, open up ODBC. The icon for this looks like this:
When you open this up, you end up with a screen like this:
![]()
Select the System DSN tab. If you havent done any work with user defined DSN's,
this should be empty. Select the Add button. You will get a screen which looks
like this: ![]()
Select the Microsoft Access driver. Click on the finish button. You will
now see this screen: ![]()
In the Data Source Name text field, enter a name which you wont forget, as this
will be the way you will call your database. For the purposes of this tute, enter
'WebTute'. The description text field is for your purposes as you may want to
manage your DSN connections later.
Finally, select the Select button. From this menu, choose the Access
database you initially created.
And that's it! your ODBC connction is done! Now to interface with it.
Interfacing With Database
Ok, now we can get down to the fun part, interfacing with a database!
We first create 2 php files. One to act as a form to get data from the user and
another to actually process the command. I know there are more elegant ways of
doing this. However, I was after a way which would be the easiest to understand.
The first PHP file is as follows. It is the form into which the user enters information.
You should be able to copy and paste the code into you favourite editor. You can
call this file whatever you want. I have called it FormInput.php3.
The code on the prior page is pretty common place. Now we actually interface with the database.
We can do this using the inherent ODBC functions within PHP and SQL. As the above
form says, the action is going to be DataAccess.php3. So copy and paste the code
below into the file DataAccess.php3.
Now you should be ready to go! In this example, i havent done any deletion of records.
However, as you can see, if you modify the variable SQL_Exec_String, you can delete
specific records as well.
I hope this has been of use to you.
--Sid
|