?
Solved

ODBC Connection to Access database with PHP

Posted on 2011-02-16
10
Medium Priority
?
321 Views
Last Modified: 2013-12-13
I followed the steps here:
http://www.devasp.com/samples/dsn_access.asp

and created a DSN, which went OK.

Then I tried to use this code to access it, but it keeps failing. $conn is empty.
 
<?php
	$conn=odbc_connect('MCDB','phpadmin','********!');
	if (!$conn)
	{
		exit("Connection Failed: " . $conn);
	}
	else
	{
		echo "Connection Established";
	}
	odbc_close($conn);
?>

Open in new window


What am I doing wrong?
0
Comment
Question by:DrDamnit
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
10 Comments
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 34911644
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 34911657
If so... Seems ok but double check:
DSN name ? Is it the same ?
Are you providing good password ?
0
 
LVL 32

Author Comment

by:DrDamnit
ID: 34911688
Since this is a Windows 2k8 box, there is no user and password because I have used a system DSN.

In that same vein, I have manually added some user / passwords to the DSN, and I have also tried authenticating with the system administrator credentials (with and without the DOMAIN\User format). All to no avail.

ODBC is already installed on a Windows SBS 2008 box, so I don't think I need to install anything else. I did, however have to install the access drives, but that went ok.
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 34911743
Does this work without providing ANYTHING ?
$conn=odbc_connect('MCDB','','');
0
 
LVL 32

Author Comment

by:DrDamnit
ID: 34912656
No joy.

I have set the file permissions to this as Everyone = Full Access (for the folder that contains this file). Still didn't work.

Thoughts?
0
 
LVL 32

Author Comment

by:DrDamnit
ID: 34912672
This is how I set it up... System Data Source Configuration Advanced Options
0
 
LVL 17

Accepted Solution

by:
Shinesh Premrajan earned 2000 total points
ID: 34914833
you need to try with these

$connection = odbc_connect("Driver={Microsoft Access Driver (*.mdb)};Dbq=$mdbFilename", $user, $password);

Hope this helps
0
 
LVL 32

Author Comment

by:DrDamnit
ID: 34925316
Still fails. Just to beclear, dbq should be the DSN or the path to the file?
0
 
LVL 32

Author Closing Comment

by:DrDamnit
ID: 34925342
The key was to do a DSN-less connection using the full path. Thanks!
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 34925403
Isn't that the thing suggested by the first post ?
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question