Solved

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

Posted on 2010-09-24
4
640 Views
Last Modified: 2012-08-14
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
Comment
Question by:robthomas09
  • 2
  • 2
4 Comments
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 33755766
"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
 

Author Comment

by:robthomas09
ID: 33756539
Sorry I didnt make that clear enough - we have an IP address and are substituting "localhost" in the above examples - thanks!
0
 
LVL 59

Accepted Solution

by:
Kevin Cross earned 500 total points
ID: 33756601
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
 

Author Comment

by:robthomas09
ID: 33756908
thanks for the comment - trying that  now
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Creating and Managing Databases with phpMyAdmin in cPanel.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

746 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