need help with connecting to Access database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gcapp
Forum Newbie
Posts: 14
Joined: Thu Jun 01, 2006 8:59 am

need help with connecting to Access database

Post by gcapp »

Hello,

I am new to php and I am having problems connecting to my Access database. The database is in the folder:
C:\inetpub\wwwroot folder.

I created a odbc connection. My database is called Accord and the connection is called Accord as well. I used it as a system database.

My php code looks like this:

Code: Select all

//$db = 'C:\\Inetpub\\wwwroot\\Accord.mdb';

//$conn = new COM('ADODB.Connection') or exit('Cannot start ADO.');
//$conn->Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=$db") or exit('Cannot open with Jet.');
//$conn->Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=$db") or exit('Cannot open with driver.');

 $connect = odbc_connect("Accord", "", "");
At first I tried using the $db connection with Microsoft.Jet and I got the error "Cannot open with Jet".

Then I tried the $db with the .mdb driver and got the error "Cannot open with driver"

Then I tried using the obdc connection (that's why it is not commented out) and I am getting an error which states:

Warning: odbc_connect() [function.odbc-connect]: SQL error: , SQL state 00000 in SQLConnect in c:\Inetpub\wwwroot\accord\info.php on line 90. Line 90 being this line:

$connect = odbc_connect("Accord", "", "");


So can someone help me to connect to my Access database. I have been doing research on this, but can't seem to get it to work.

Any help would be appreciated.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Some of this might be because of the connection string and some may be caused by the database itself. Have you looked into creating a DSN? Also, take a look at this website about connection strings. Hope it helps.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

can you connect to the datasource outside of php? IE, even from the datasource manager in windows?
Post Reply