Click to See Complete Forum and Search --> : ODBC Not Working
shuklasanjeev
09-09-2002, 09:12 PM
Hi,
I am trying to connect to MSAccess database using ODBC but getting following error message:
Warning: SQL error: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified, SQL state IM002 in SQLConnect in D:\wwwcode\php_codes\odbc_test.php on line 15
Warning: odbc_close(): supplied argument is not a valid ODBC-Link resource in D:\wwwcode\php_codes\odbc_test.php on line 30
I am using following script to access the database:
<?php
//connect to the database
$connectionstring = odbc_connect("testdsn","","");
odbc_close($connectionstring);
?>
This is System DSN and works fine in ASP and Coldfusion.
Please advise how to resolve this.
Thanks.
dotwebbie
09-11-2002, 03:34 PM
If that's your entire script, why in the world is it saying that there are errors on lines 15 and 30?
<?php
$conn=odbc_connect("testdsn", " ", " ");
odbc_close($conn);
?>
Try that. Make sure that there are no spaces before or after the opening and closing marks.
After doing a little reading up at php.net, I found this:
Beware that when creating DSN under win32, you must make them comp DSN not user DSN. Since the httpd is ran as a system service, not as the current user, the service won't see the DSN you, as a user, have created. I know it's simple, it's logical afterward, but I lost so much time asking myself why it didn't work, that I decided to post this hint to avoid this hassle to anyone else.
Also, this:
for iodbc+openlink to connect to SQL 7 on NT from Linux+php3
I had to put the UID and PWD into the DSN string otherwise it wont recognise the username and password:
odbc_connect("DSN=DataSource","username","password"); doesnt see user or password
but
odbc_connect("DSN=DataSource;UID=UserName;PWD=Password","","");
works fine
shuklasanjeev
09-11-2002, 05:23 PM
Hi,
There are other lines as well, which have been commented, thats why the error message shows line 15.
Following is the full script :
=========================================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>PHP ODBC Check</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF">
<?php
$connectionstring = odbc_connect("testdsn","","");
//odbc_close($connectionstring);
?>
</body>
</html>
============================================
And following is the error message:
============================================
Warning: SQL error: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified, SQL state IM002 in SQLConnect in D:\wwwcode\php_codes\odbc_test.php on line 13
============================================
And there is no space beteen opening and closing bracket in odbc_connect syntax.
Please let me know if you have any other clue.
ONE MORE INFO : I AM RUNNING THIS SCRIPT IN
WINDOWS 2000 ADVANCE SERVER SP2/ IIS5.0 / IE5.5
Thanks.
dotwebbie
09-11-2002, 07:53 PM
Hm . . .
Okay, try
<?php
$conn=odbc_connect("DSN=testdsn","","");
odbc_close($conn);
?>
Be sure to put the DSN=testdsn in.
shuklasanjeev
09-11-2002, 09:36 PM
:(
Thanks.
But I still get the same error.
I have seen this error reported by a lot of people in other forum as well, so looks like a common missing parameter or setting.
dotwebbie
09-12-2002, 01:27 PM
For once I wish I actually had worked with ODBC . . . Here's a thought, after looking through phpBB's dbal, I found nothing different. So try adding a username and password. Worth a try at least . . .
shuklasanjeev
09-12-2002, 01:53 PM
I do not have any username and password for MSAccess DSN.
Thanks.
dotwebbie
09-12-2002, 02:19 PM
I know, set one.
shuklasanjeev
09-23-2002, 05:25 PM
Guys,
I guess I have found the bug:
If you install PHP4.2.3 from self install file and use it under Windows 2000 Advance Server / IIS 5.0 Then ODBC function of PHP does not work.
I replaced IIS5.0 with Apache2.0 on Windows 2000 Advance Server, and it worked.
So, we have to check the php4.2.3 buglist for this issue.
Thanks to everybody for trying to help me out.
dotwebbie
09-23-2002, 07:26 PM
The self-install (the .exe if that's what you are referring to . . .) is for cgi only. The zip file let's you use mod_php which may or may not have the same problem . . . Have you tried mod_php?
shuklasanjeev
09-23-2002, 07:36 PM
Hi,
I did try with zipped version of php4.2.3 and tried both php.exe as well as php4isapi.dll under IIS5.
But nothing worked.
I didn't try mod_php, because I think that works only under apache.
Thanks.
dotwebbie
09-23-2002, 07:46 PM
Yes, I thought I saw Apache in there somewhere. Sorry, my fault.
PHP Builder
Copyright Internet.com Inc. All Rights Reserved.