Solved

MySQL - mysql_connect won't connect :(

Posted on 2009-04-05
9
504 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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 110

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 110

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

735 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