Solved

ODBC Connection to Access database with PHP

Posted on 2011-02-16
10
306 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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
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 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

815 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

11 Experts available now in Live!

Get 1:1 Help Now