Solved

MySQL - mysql_connect won't connect :(

Posted on 2009-04-05
9
498 Views
Last Modified: 2012-05-06
I am using ...
<?php
$link = mysql_connect('localhost', 'mysql_user', 'password');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>
... to connect to a database on a Plesk 9 VPS.  I get this error ...
Could not connect: Access denied for user 'mane_fileuser'@'localhost' (using password: YES)

any help would be awesome as I am stuck :)
0
Comment
Question by:mycroftx
  • 2
  • 2
  • 2
  • +2
9 Comments
 
LVL 14

Expert Comment

by:shobinsun
ID: 24071801
Hello,

Error means that you are trying to connect with the user "mane_fileuser" with password option YES is not allowed.

So try with no password.

means:

<?php
$link = mysql_connect('localhost', 'mysql_user', '');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>


Regards.
0
 
LVL 12

Expert Comment

by:lexxwern
ID: 24071890
Just check the login details. On some hosts you may need to prefix your hosting username. So check with them for the exact details.
0
 

Expert Comment

by:coolguy2009
ID: 24071915
Hi also in some server it is not localhost.

yourusername.localhost

Also check whether the login details are correct.
0
 
LVL 4

Author Comment

by:mycroftx
ID: 24071929
I tried it with no password and got the same result, I tried sybtracting the maner_ from the user name with the same result.  Ive got a ticket in with the host but they are saying "Unfortunately, we cannot troubleshoot or write connection strings since it is beyond our support scope."
Ive asked a friend to try the code (function usage is the same) on his web server and it works.  So crap :(
0
Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

 
LVL 14

Expert Comment

by:shobinsun
ID: 24072004
Hello,

If you have mysql prompt then change the mysql password of the recognized user by:

mysql>UPDATE user SET password=password(newpassword) WHERE user=username;

hope this will help you.

Regards.
0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 24072488
Regarding this, "they are saying "Unfortunately, we cannot troubleshoot..."

You are being mistreated if that is the best answer they can come up with.

Call your hosting company back and tell the tech support people that they will lose a client immediately if they do not resolve this.  Show them a link to this question and my answer here.  Make them read it out loud to you over the phone, so you know they have their eye on the ball.  They almost certainly have heard this question before and have a FAQ or something like that with examples of how to connect and select a data base.

Here is the sample code I use to teach the connect and select basics.  Look for the four variables near the question marks - they all have to be correct.  

HTH, ~Ray
<?php // RAY_mysql_example.php

error_reporting(E_ALL);
 
 

// CONNECTION AND SELECTION VARIABLES FOR THE DATABASE

$db_host = "localhost"; // ?? PROBABLY THIS IS OK

$db_name = "??";        // ?? GET THESE FROM YOUR HOSTING COMPANY

$db_user = "??";

$db_word = "??";
 

// CONNECT TO THE DATA BASE SERVER

if (!$db_connection = mysql_connect("$db_host", "$db_user", "$db_word"))

{

   $errmsg = mysql_errno() . ' ' . mysql_error();

   echo "<br/>NO DB CONNECTION: ";

   echo "<br/> $errmsg <br/>";

}
 

// SELECT THE DATA BASE

if (!$db_sel = mysql_select_db($db_name, $db_connection))

{

   $errmsg = mysql_errno() . ' ' . mysql_error();

   echo "<br/>NO DB SELECTION: ";

   echo "<br/> $errmsg <br/>";

   die('NO DATA BASE');

}
 
 
 

// MAKING A QUERY AND TESTING THE RESULTS

$sql = "SELECT id FROM my_table WHERE username='$username'";

$res = mysql_query($sql);
 

// IF mysql_query() RETURNS FALSE, THERE IS DIAGNOSTIC INFORMATION AVAILBALE

if (!$res)

{

   $errmsg = mysql_errno() . ' ' . mysql_error();

   echo "<br/>QUERY FAIL: ";

   echo "<br/>$sql <br/>";

   die($errmsg);

}

// IF WE GET THIS FAR, THE QUERY SUCCEEDED AND WE HAVE A RESOURCE-ID IN $res SO WE CAN NOW USE $res IN OTHER MYSQL FUNCTIONS
 
 
 

// DETERMINE HOW MANY ROWS OF RESULTS WE GOT

$num = mysql_num_rows($res);

if (!$num)

{

   echo "<br/>QUERY FOUND NO DATA: ";

   echo "<br/>$sql <br/>";

}

else

{

   echo "<br/>QUERY FOUND $num ROWS OF DATA ";

   echo "<br/>$sql <br/>";

}
 
 
 

// ITERATE OVER THE RESULTS SET TO SHOW WHAT WE FOUND

echo "<pre>\n"; // MAKE IT EASY TO READ

while ($row = mysql_fetch_assoc($res))

{

   var_dump($row);

}

Open in new window

0
 
LVL 4

Author Comment

by:mycroftx
ID: 24073622
that was awesome, got all the info I needed plus alot to learn from :)
0
 

Expert Comment

by:coolguy2009
ID: 24074353
@Ray_Paseur: Great tutorial. Ray Rocks!!!

@mycroftx: In Dreamhost support is good.I am following Ray's way:)
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 24108030
Thanks for the points.  I have heard nothing but good about Dreamhost, and the only reason I do not use them is that they have very rigid limitations on how many emails you can send in a day.  Because I host my church web site and we have to send 2,000+ emails one day every week, they don't work for me.  That is an unfortunate circumstance.  OTOH, I am very happy with ChiHost.com where I am currently hosted.

best to all, ~Ray
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now