Access DB in PHP

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Using Ubuntu and have installed mdbtools and php5-odbc but not sure
where to go from here.

It'd be great if someone would point me in the right direction as to
connecting to the database and how.

Re: Access DB in PHP

Quoted text here. Click to load it

The PHP ODBC commands can be found at:

I have never used the odbc commands for accessing an access DB, but,
you will need to start out using an odbc_connect command like:

$db_conn = odbc_connect("DRIVER={Microsoft Access Driver (*.mdb)};
"password", "SQL_CUR_USE_ODBC");

After making your connection to your database, you will be able to
submit queries, etc. you can run queries against your tables using a
command similar to the following:

$qry_res = odbc_exec($db_conn,"SELECT * FROM TABLE1");

Now, there are different commands that can be used once you get the
data into your resource pointer $qry_res in the command above, if you
wanted to just return an HTML table containing the data from the
query, you could use the command:


However the above in most cases may be virtually useless, likely you
will prefer to store the values for the table in an array, or fetch a
row from the results one at a time, to do something with it:

$data_arr = odbc_fetch_array($qry_res,INT); // INT is indicating the
row retrieved into the array

In most cases it would probably be best to use the fetch array
command, but the other commands available for retrieving data could be
read up on at the link above.

After finishing with queries etc. you will want to issue the following

odbc_close($db_conn); Or odbc_close_all();

Site Timeline