Solved

ODBC Connection to Access database with PHP

Posted on 2011-02-16
10
304 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
  • 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
 
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
Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

 
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:
shinuq earned 500 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
The viewer will learn how to count occurrences of each item in an array.

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now