Solved

ODBC Connection to Access database with PHP

Posted on 2011-02-16
10
310 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
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
The viewer will learn how to dynamically set the form action using jQuery.

733 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