Solved

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

Posted on 2010-09-24
4
647 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
append to an ms access field 6 43
multiple application databases same MSSQL instance 5 68
WebSite Direction 1 54
ESX 6.0 Best Practices for datastore size 5 125
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
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…

839 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