ODBC is an Application Programming Interface (API) that allows us to connect to a
data source, for example MS Access database. In large projects it is not a recommended practice to access databases through ODBC, however.
How to Create an ODBC Connection?
With the help of an ODBC connection, we can connect to any database, on any computer in our
network, as long as an ODBC connection is available.
Just follow the below mentioned steps to create an ODBC connection to a MS Access Database:
It is important to note here that this configuration has to be done on the computer where the web site is
located. If you are running IIS on your own computer, the
instructions above will work fine, but if your web site is located on a remote server, you have
to have physical access to that server. You can also ask your web hosting service provider to to set up a DSN for you.
- Open the Administrative Tools from your Control Panel.
- Double-click on the Data Sources (ODBC) icon inside.
- Choose the System DSN tab.
- Click on Add in the System DSN tab.
- Select the Microsoft Access Driver. Click Finish.
- In the next screen, click Select to locate the database.
- Give the database a Data Source Name (DSN).
- Click OK.
Connecting to an ODBC Data Source
The odbc_connect() function is used to connect to an ODBC data source. This function
takes four parameters:
the data source name,
and an optional cursor
The odbc_exec() function is used to execute an SQL statement.
PHP ODBC Example
The following code example creates a connection to a DSN called northwind, with no
username and no password and then it creates an SQL and executes it:
$sql="SELECT * FROM customers";