Solved

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

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
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…

713 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