Results 1 to 8 of 8
  1. #1
    Join Date
    Jun 2011
    Posts
    4

    Unhappy Unanswered: odbc connection not working

    I'm trying to access a .mdb database file, but I cannot open a connection.

    I know that the path of the file is right, I don't receive the 'Database file does not exist' error I wrote (which was popping up earlier when the file was in the wrong place).

    I have been looking online for the proper way to open an ODBC connection to a Microsoft Access database, but I still can't find what is wrong with my code.

    PHP Code:
    $dbq "db/hsc.mdb";
        
    if    (!
    file_exists($dbq)) 
        { 
            echo 
    "Sorry!<br />Database file: <b>$dbq does not exist</b>"
        }

    $db_conn odbc_connect("Driver={Microsoft Access Driver (*.mdb)};Dbq=$dbq"$username$password,'SQL_CUR_USE_ODBC');
            
    $this->db_connection $db_conn;
            
    if(
    $db_conn){echo "Yay! there is a connection!";}
    else{echo 
    "There is no connection :(";} 
    When the code runs, I get the error message "There is no connection :(" because $db_conn is 0. How do I fix this?

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    try an or die when you try to establish the connection
    one of the problems of PHP is that it doesn't die automatically.
    you need to establish why the connection is failing
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Jun 2011
    Posts
    4
    adding an 'or die' did nothing except break my page. Nothing shows up now but white.

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    or die (echo "MYSQL crapped out with the following error message:-".mysql_errno()."; ".mysql_error()));
    I'd rather be riding on the Tiger 800 or the Norton

  5. #5
    Join Date
    Jun 2011
    Posts
    4
    hmmm. so now my line of code reads:
    PHP Code:
    $db_conn odbc_connect("Driver={Microsoft Access Driver (*.mdb)};Dbq=$dbq$username$password,'SQL_CUR_USE_ODBC'" 
            
    or die (echo "MYSQL error message:-".mysql_errno()."; ".mysql_error())); 
    and nothing happens except a blank page. My error message doesn't come up, but the script dies and refuses to go on to the HTML that describes the page, I think. I'm not sure what's happening?

  6. #6
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    sorry my bad
    there is no point repeating the MySQL error & description as these are specific to MySQL and you are using ODBC to a Microsoft JET db.
    so look up what the equivalent error number and messages are in ODBC / JET

    you may also need to turn on full error reporting, which IIRC is going to be soemthing like
    error_reporting(E_ALL);
    I'd rather be riding on the Tiger 800 or the Norton

  7. #7
    Join Date
    Jun 2011
    Posts
    4
    no, I mean I don't get any message at all. I don't even get the "MYSQL error message:-" which is just text I asked it to print. Even if I ask it to just print a bland "This page is broken, sorry" or something, it's not showing up. I think it's dying before it gets to printing?

  8. #8
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    so turn on the full error reporting
    whether you need E_ALL or E_ALL || E_NOTICE or whatever is up to you
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •