how to use ms access database in php

Discussion in 'PHP' started by bhuppi890109, Sep 20, 2010.

  1. #1
    hey frnds i want to know how to use MS ACCESS in the php ....
     
    bhuppi890109, Sep 20, 2010 IP
  2. lukeg32

    lukeg32 Peon

    Messages:
    645
    Likes Received:
    19
    Best Answers:
    1
    Trophy Points:
    0
    #2
    Depending on what you are trying to achieve, you will need to create a DSN and use the ODBC functions that are built in.

    Start here for more information:
    http://php.net/manual/en/function.odbc-connect.php

    If you arent sure about DSN' and need mroe information, see here:
    http://www.w3schools.com/PHP/php_db_odbc.asp

    Of course, it could be argued that it would be better to export your database to mysql, postgres or something else rather than using access, but as said above, it depends what you are trying to achieve.
     
    lukeg32, Sep 20, 2010 IP
  3. axelay

    axelay Peon

    Messages:
    54
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    As lukeg32 mentionned,

    You first need to create the ODBC on the machine the script will run then use the php functions to connect to it. eg:
    $odbc = odbc_connect ('odbc_name', 'username', 'password') or die('Could Not Connect to ODBC Database!');
    
    $query = odbc_exec($odbc, "SELECT * FROM mytable") or die (odbc_errormsg());
    while ($row = odbc_fetch_array($query))
    {
    	// Do something here
    }
    odbc_close ($odbc);
    
    Code (markup):
    aXe
     
    axelay, Sep 21, 2010 IP