Jump to content


Do I have a database connection? Access denied for user 'ODBC'@'localhost' (using password: NO)


2 replies to this topic

#1 Michael Howes

    Newbie

  • Members
  • Pip
  • 0 posts

Posted 04 September 2010 - 03:37 AM

I'm brand new to MySQL and PHP (don't kill me but I develop asp.net apps)
I just installed
MySQL (5.1.11)
Apache (2.2)
PHP (5.2.14)

I'm doing a friend a favor and adding new features to a site which is loads of fun since I've never done PHP before.
One important thing is that this code is currently running and has been for a while on his host.

I almost have the existing code running on my machine but just ran into a problem executing queries
Getting a MySQL error of "Access denied for user 'ODBC'@'localhost' (using password: NO)"

There is a connect.php file that is included in the page with the mysql_query call
This fails with the above error
When I load connect.php directly it is connecting successfully
I tried moving the code that connects into the same page with the mysql_query call and IT WORKS

$result = @mysql_query("SELECT * FROM kfth_bands where id='18'");
note that the resource $link_identifier is not passed in

as I mentioned this is code that runs on the host but it's not running on my newly setup machine
and since I'm new to this I'm just guessing since I can make the code work by moving the connect code into the same .php file as the mysql_query call.

Is the connection somehow going out of scope? Is this a php setting? or apache setting?

thanks
mike

#2 Michael Howes

    Newbie

  • Members
  • Pip
  • 0 posts

Posted 04 September 2010 - 06:29 AM

could my issue have something to do with a difference between

include("connect/db_connect.php");

and

include 'connect/db_connect.php';

??

my test connect and sql worked when

huh?

#3 Shoel

    Administrator

  • Administrators
  • 125 posts

Posted 06 September 2010 - 12:00 AM

Hi Michael,

Welcome to PHPTalk.com!

Apologies for not having replied sooner, must have slipped my mind after seeing that you had resolved it yourself.

include 'foo.php' and include('foo.php') are the same - so that should not matter. I am guessing you might have done something else in-between that resolved the issue. I believe ODBC will be the default mysql user on your system - and that you somehow ended up invoking mysql_connect() without a username or password passed to it. (Thus it tried connecting with a default user and NO password.)

If you are able still having issues with it and are able to reproduce the issue, feel free to post code and I can take a closer look.

Kind regards,
- S.
Hi there! If you found this post useful, or used this information to help others, we would greatly appreciate a link back to our forum from your website/blog. Thanks! =)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users