Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2010-09-24
4
Medium Priority
?
659 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 60

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 60

Accepted Solution

by:
Kevin Cross earned 2000 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

Plesk WordPress Toolkit

Plesk's WordPress Toolkit allows server administrators, resellers and customers to manage their WordPress instances, enabling a variety of development workflows for WordPress admins of all skill levels, from beginners to pros.

See why 2/3 of Plesk servers use it.

Question has a verified solution.

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

Your data is at risk. Probably more today that at any other time in history. There are simply more people with more access to the Web with bad intentions.
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

721 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