Connecting Tech Pros Worldwide Forums | Help | Site Map

Access denied for user 'ODBC'@'localhost' (using password: NO)

Familiar Sight
 
Join Date: Oct 2008
Posts: 128
#1: Aug 26 '09
i hav downloaded php script from a site but while running it gives error
Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\wamp\www\forum\db.class.inc.php on line 29
i use this for my connection and works well
$conn=mysql_connect("localhost","root","");
while this doesnt work
function db($localhost='localhost',$database='ncstd',$usern ame='root',$password='')

kindly help as i m new to php

Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,658
#2: Aug 26 '09

re: Access denied for user 'ODBC'@'localhost' (using password: NO)


Quote:

Originally Posted by kkshansid View Post

while this doesnt work
function db($localhost='localhost',$database='ncstd',$usern ame='root',$password='')

then you should check, whether db() works correctly.
Familiar Sight
 
Join Date: Oct 2008
Posts: 128
#3: Aug 26 '09

re: Access denied for user 'ODBC'@'localhost' (using password: NO)


Expand|Select|Wrap|Line Numbers
  1. function db($localhost='localhost',$database='ncpul1',$username='root',$password=''){
  2.         $this->localhost=$localhost;
  3.         $this->database=$database;
  4.         $this->username=$username;
  5.         $this->password=$password;
  6.         $this->conn=mysql_connect($this->localhost,$this->username,$this->password);//line29
  7.         mysql_select_db($this->database,$this->conn);
  8.     }
i dont think there is any error in this function
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,658
#4: Aug 26 '09

re: Access denied for user 'ODBC'@'localhost' (using password: NO)


just to make sure… how do you call db()?
Familiar Sight
 
Join Date: Oct 2008
Posts: 128
#5: Aug 26 '09

re: Access denied for user 'ODBC'@'localhost' (using password: NO)


on index page after including connection file function call as
Expand|Select|Wrap|Line Numbers
  1. $db=new db($DB_LOCALHOST,$DB_DATABASE,$DB_USERNAME,$DB_PASSWORD);
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,658
#6: Aug 26 '09

re: Access denied for user 'ODBC'@'localhost' (using password: NO)


is $DB_USERNAME a variable or a constant?
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,948
#7: Aug 26 '09

re: Access denied for user 'ODBC'@'localhost' (using password: NO)


In your first example, you say it works when user = root. However, the error is saying that you're connecting as 'ODBC' (I assume that's no username). So you're doing something wrong.
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,658
#8: Aug 26 '09

re: Access denied for user 'ODBC'@'localhost' (using password: NO)


I suspect that’s the username used when no username ("", null) was given. if the username is indeed saved as DB_USERNAME (you* hardly name variables uppercase) it would be the explanation.

* at least the ones who read the naming convention
Reply