0

When I run the following page on my local development environment I'm getting a timeout error on the TCP connection. I've inherited this site recently from another developer. I've pulled all the files on the server and dropped them into my /Users/mycomputer/Sites/testsite.com folder on my MacBook Pro running Lion.

The code I'm running (obviously I've sanitized the code for posting here):

<?php
mysql_connect("mysqldb", "usernamehere", "passwordhere") or die(mysql_error());
echo "Connected to MySQL<br />";
mysql_select_db("test") or die(mysql_error());
echo "Connected to Database";
?>

And the error:

Warning: mysql_connect() [function.mysql-connect]: [2002] Operation timed out (trying to connect via tcp://mysqldb:3306) in /Users/mycomputer/Sites/testsite.com/dbtest.php on line 2
Warning: mysql_connect() [function.mysql-connect]: Operation timed out in /Users/mycomputer/Sites/testsite.com/dbtest.php on line 2
Operation timed out

Any ideas on where I've gone wrong? I'm pretty unskilled in the PHP world so, forgive my ignorance. If this were ColdFusion I would suspect a datasource problem.

5
  • 1
    Are you having the MySQL database server running on your machine? Commented Dec 19, 2011 at 18:47
  • Is "mysqldb" a sanitized value? If you're doing everything locally that should probably be "localhost". Commented Dec 19, 2011 at 18:48
  • "mysqldb" is a sanitized value but it's very close to the original value. The original did not call an ip address or anything like that. Commented Dec 19, 2011 at 18:50
  • I do have mysql running on my local machine but I want to use the remote mysql db during testing. To be more specific, I have not created a copy of the database on my local machine... Commented Dec 19, 2011 at 18:52
  • I'm able to navigate to the phpMyAdmin at the site's http://www.sitename.com/phpMyAdmin/ and log in to see the database that way... What do I need from the host in order to connect to the remote db? Commented Dec 19, 2011 at 19:01

1 Answer 1

2

Firstly, you need to check whether your website allows external IPs to connect to the DB. If they do, you might have to add your current IP to the list of allowed IPs.

Then, you need to connect to the DB using their external db address. If you do all that correctly, this should work. You error shows that it can't connect to the DB.

Sign up to request clarification or add additional context in comments.

2 Comments

I was just informed that they do not allow external access to the mysql database.
To follow up, I exported the mysql database from the production server and re-created it on my local environment. The connection to the database is working in the local environment now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.