Solved

ODBC Connection to Access database with PHP

Posted on 2011-02-16
10
316 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

717 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