Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

When MS Acces db is opened, trying to connect to odbc fails

GoodGrendelGoodGrendel Posts: 61Member
Hi all, when i have my Microsoft Acces database opened, and viewing some tables, and then i'm going to try to visit a php page i made viewing information from the database it gives this error:

Warning: odbc_connect(): SQL error: [Microsoft][ODBC Microsoft Access Driver] Could not use '(unknown)'; file already in use., SQL state S1000 in SQLConnect in D:inet-srvweb-root estFA.php on line 3

Now, what i'd like to have is where the php can always read and modify whats in the database, even when the database is opened in ms access.

Anyway, any clue on how to get rid of this error, and being able to work with both the php-odbc and the ms access at the same time?

kind regards,
Ivo Jonker

Comments

  • skylarskylar Posts: 82Member
    I have no idea =P

    Perhaps you could read the data, store it in local variables and close the connection each time you need to do something..

    I dunno, and i kind of doubt anyone else here will =
    [b][blue]Snoochie Boochies[/blue][/b]

  • WitchHunterWitchHunter Posts: 3Member
    [b][red]This message was edited by WitchHunter at 2004-6-26 9:6:2[/red][/b][hr]
    [b][red]This message was edited by WitchHunter at 2004-6-26 9:4:54[/red][/b][hr]
    : I have no idea =P
    :
    : Perhaps you could read the data, store it in local variables and close the connection each time you need to do something..
    :
    : I dunno, and i kind of doubt anyone else here will =
    : [b][blue]Snoochie Boochies[/blue][/b]
    :
    :

    How to connect and get data from an Access-Database:

    ... and put 'em into an Array using keys and values
    use cut & paste, should work

    <?PHP

    $db = "db1.mdb";

    $db_connection = new COM("ADODB.Connection");
    $db_file = realpath($db);
    $db_path = substr($db_file, 0, strrpos($db_file,'\'));

    /*
    Be careful with this ... your Drivername might differ from
    this one ... depends on Windows/Office-Language, etc.
    Just open your ODBC to see what the right name is
    */

    $db_connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=".$db_file."; DefaultDir=".$db_path;

    $db_connection->open($db_connstr);
    $rs = $db_connection->execute($sql);

    $fld = $rs->Fields;
    $field_count = $fld->Count;

    $cnt = 0;
    while (!$rs->EOF)
    {
    for ($i=0; $i < $field_count; $i++)
    {
    $tmp = $rs->Fields($i);
    $valueArr[$cnt][$tmp->name] = $tmp->value;
    }
    $cnt++;
    $rs->MoveNext(); // updates fields!
    }

    // cleaning up
    $rs->Close();
    $db_connection->Close();
    $rs=null;
    $db_connection=null;
    ?>

    Hope that helps,

    greet$
    WitchHunter




Sign In or Register to comment.