|
Posted by davidkruger on 07/27/07 18:48
On Jul 25, 10:06 am, MFB IT <scas...@mfblouin.com> wrote:
> 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.
The PHP ODBC commands can be found at:
http://us.php.net/odbc
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)};
DBQ=PATH TO ACCESS DATABASE LOCATED HERE", "ADODB.Connection",
"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:
odbc_result_all($qry_res);
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
commands:
odbc_free_results($qry_res);
odbc_close($db_conn); Or odbc_close_all();
[Back to original message]
|