Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 662
  • Last Modified:

MySQL Connect.php - Can't connect to MySQL server

Hello experts,

Every time I try and connect with the below PHP code in my connect.php file, I receive the error:
Warning:  mysql_connect() [function.mysql-connect]: Can't connect to MySQL server on 'localhost' (113) in /home/content/k/i/g//html/website/connect.php on line 6
Can't connect to MySQL

(In the above and below example - localhost is our IP address).

<?php
$hostname='localhost'; //// specify host, i.e. 'localhost'
$user='######'; //// specify username
$pass='######'; //// specify password
$dbase='ProdDB'; //// specify database name
$connection = mysql_connect("$hostname" , "$user" , "$pass")
or die ("Can't connect to MySQL");
$db = mysql_select_db($dbase , $connection) or die ("Can't select database.");
?>

We have verified that the hardware firewall has allowed port 3306 and port 80.  There is no software firewall.  We are going from siteA (test website) to SiteB (where the Database is stored with an IP Address).

Thoughts?

Thanks in advance!
0
robthomas09
Asked:
robthomas09
  • 2
  • 2
1 Solution
 
Kevin CrossChief Technology OfficerCommented:
"We are going from siteA (test website) to SiteB (where the Database is stored with an IP Address)."

If your web-site is siteA and your database is siteB, then the $hostname should not be 'localhost', but instead the dns hostname for the target database host or its IP address --- maybe you are just simplifying for the question, but just thought I would mention that given the question text.
0
 
robthomas09Author Commented:
Sorry I didnt make that clear enough - we have an IP address and are substituting "localhost" in the above examples - thanks!
0
 
Kevin CrossChief Technology OfficerCommented:
The $user value you are using, do you know if it has been granted privileges to connect remotely?  For example, some secure setups of MySQL will only allow root to connect from @localhost , so double check that the user's rights are set using 'username' or 'username'@'%'
0
 
robthomas09Author Commented:
thanks for the comment - trying that  now
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now