Solved

MySQL - mysql_connect won't connect :(

Posted on 2009-04-05
9
502 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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 109

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 109

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP installation issues 11 61
insert row field data graphically 4 24
insert into database through form with dynamic fields. 2 31
paypal ipn url 5 58
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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 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…
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.

777 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