Solved

MySQL - mysql_connect won't connect :(

Posted on 2009-04-05
9
500 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

864 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

16 Experts available now in Live!

Get 1:1 Help Now