If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > PHP > odbc connection not working

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-24-11, 16:34
plzz plzz is offline
Registered User
 
Join Date: Jun 2011
Posts: 4
Unhappy 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?
Reply With Quote
  #2 (permalink)  
Old 06-25-11, 17:02
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,262
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 my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #3 (permalink)  
Old 06-27-11, 09:14
plzz plzz is offline
Registered User
 
Join Date: Jun 2011
Posts: 4
adding an 'or die' did nothing except break my page. Nothing shows up now but white.
Reply With Quote
  #4 (permalink)  
Old 06-27-11, 13:14
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,262
or die (echo "MYSQL crapped out with the following error message:-".mysql_errno()."; ".mysql_error()));
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #5 (permalink)  
Old 07-06-11, 09:14
plzz plzz is offline
Registered User
 
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?
Reply With Quote
  #6 (permalink)  
Old 07-06-11, 09:43
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,262
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 my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #7 (permalink)  
Old 07-06-11, 11:15
plzz plzz is offline
Registered User
 
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?
Reply With Quote
  #8 (permalink)  
Old 07-06-11, 13:16
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,262
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 my Versys or my Tiger 800 let alone the Norton
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On