Current location: Hot Scripts Forums » Other Discussions » Database » mysql_connect(): Access denied for user


mysql_connect(): Access denied for user

Reply
  #1 (permalink)  
Old 10-23-08, 07:19 PM
rlq rlq is offline
Newbie Coder
 
Join Date: Oct 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
mysql_connect(): Access denied for user

Hi,

I just setup Apache, MySQL, and PHP using XAMPP and did several tests, some of them are passed such as PHP info test and date test, but It failed in this following test:

code: Load.php
PHP Code:

<?php
$con 
mysql_connect("localhost","rlq","abc123");
if (!
$con)
  {
  die(
'Could not connect: ' mysql_error());
  }

if (
mysql_query("CREATE DATABASE my_db",$con))
  {
  echo 
"Database created";
  }
else
  {
  echo 
"Error creating database: " mysql_error();
  }

mysql_close($con);
?>
Test Result:
Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'rlq'@'localhost' (using password: YES) in C:\xampp\htdocs\Load.php on line 2
Could not connect: Access denied for user 'rlq'@'localhost' (using password: YES)

I need your help to continue.
Thanks

Last edited by Nico; 10-24-08 at 03:09 AM. Reason: Wrappers.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 10-25-08, 03:29 PM
digioz's Avatar
digioz digioz is offline
Community VIP
 
Join Date: Oct 2003
Location: Chicago, IL
Posts: 2,167
Thanks: 3
Thanked 8 Times in 8 Posts
Here is an obvious question. Did you add this user and password to the MySQL database?

Pete
__________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 10-27-08, 11:34 AM
rlq rlq is offline
Newbie Coder
 
Join Date: Oct 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
mysql_connect(): Access denied for user

Hi Pete,

I installed apache, php and mysql using Xampp. When install, there was no question about user name, password or ... any query. After installed, I tested phpinfo, then tested this database connection code.

However, your question to me is the answer. So can you tell me how to add the user and password to the MySQL database?

Thanks,
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 10-27-08, 11:40 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
XAMPP's default user is "root", and there is no default password, so try leaving this in blank.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 10-27-08, 12:00 PM
rlq rlq is offline
Newbie Coder
 
Join Date: Oct 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
mysql_connect(): Access denied for user

hi Nico,
I just tried to modify this line of code
$con = mysql_connect("localhost","rlq","abc123");

to
$con = mysql_connect("localhost","","");

$con = mysql_connect("localhost","rlq","abc123");

and the result is
Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xampp\htdocs\Load.php on line 2
Could not connect: Access denied for user 'ODBC'@'localhost' (using password: NO)
So what I did not correct?

thanks,
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 10-27-08, 12:02 PM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
The user. It should be "root".
PHP Code:

$con mysql_connect("localhost""root"); 

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 10-27-08, 12:07 PM
rlq rlq is offline
Newbie Coder
 
Join Date: Oct 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
hi Nico,
I tried with
$con = mysql_connect("localhost","root");

and the result is
Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'root '@'localhost' (using password: NO) in C:\xampp\htdocs\Load.php on line 2
Could not connect: Access denied for user 'root '@'localhost' (using password: NO)

thanks,
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 10-27-08, 12:31 PM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
Actually, try it this way:
PHP Code:

$con mysql_connect("localhost""root"""); 

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #9 (permalink)  
Old 10-27-08, 12:43 PM
rlq rlq is offline
Newbie Coder
 
Join Date: Oct 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
OOPS, I had "root " instead of "root". Your first suggestion is work.
thanks,
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #10 (permalink)  
Old 10-27-08, 12:48 PM
rlq rlq is offline
Newbie Coder
 
Join Date: Oct 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Peter, Nico,
I really appreciate your help. The first time I join the internet help group.
I am deeply impressed this group( can I say our group).
thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Iframe Access Denied on window.open sharijl JavaScript 3 10-01-08 10:15 AM
Warning: mysql_query() [function.mysql-query]: Access denied for user 'mylogi'@'localhost' (using pa tut123408 PHP 6 05-28-08 12:50 AM
cross server error: access is denied kuraiza JavaScript 1 03-14-06 02:31 PM
Sql Server does not exists or access denied error. pdnitin ASP.NET 2 11-15-04 01:06 AM
Permission denied when access excel obj msrnivas ASP.NET 0 12-05-03 03:18 AM


All times are GMT -5. The time now is 09:12 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.