Access DB in PHP

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • MFB IT

    #1

    Access DB in PHP

    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.

  • davidkruger@techie.com

    #2
    Re: Access DB in PHP

    On Jul 25, 10:06 am, MFB IT <scas...@mfblou in.comwrote:
    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:



    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("D RIVER={Microsof t Access Driver (*.mdb)};
    DBQ=PATH TO ACCESS DATABASE LOCATED HERE", "ADODB.Connecti on",
    "password", "SQL_CUR_USE_OD BC");

    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_c onn,"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_arra y($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_resul ts($qry_res);
    odbc_close($db_ conn); Or odbc_close_all( );

    Comment

    Working...