-3

Following the post on Connecting mysql remotely via free host,

the remote access still fails. My PHP script is stored in Xtreemhost and intends to access the MySQL database on FreeMySQL.net. If FreeMySQL.net supports remote accesss to MySQL databases (which is true), there should be no problem with my PHP script run on another free web hosting server.

Can anyone tell me what is wrong with my remote access to my MySQL database? Thank you.

<?php
// $server = "example.com";
$server = "sql.example.com";
$username = "tinfanide";
$password = "MyPassword";
$database_name = "tinfanide";

$connect = mysql_connect($server,$username,$password) or die(mysql_error());
mysql_select_db($database_name,$connect);

mysql_close($connect);    
?>
Community
  • 1
  • 1
Tin Amaranth
  • 683
  • 2
  • 12
  • 23
  • 3
    So, what's actually going wrong? What error message are you getting? Be precise, please. Copy/paste would be ideal. Speaking of copy/paste: **Heads up!** The next major release of PHP is *deprecating* the `mysql_` family of functions. Now would be a great time to [switch to PDO](http://php.net/book.pdo) or [mysqli](http://php.net/book.mysqli). – Charles Dec 28 '12 at 09:41
  • 1
    [**Please, don't use `mysql_*` functions in new code**](http://bit.ly/phpmsql). They are no longer maintained [and are officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). See the [**red box**](http://j.mp/Te9zIL)? Learn about [*prepared statements*](http://j.mp/T9hLWi) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://j.mp/QEx8IB) will help you decide which. If you choose PDO, [here is a good tutorial](http://j.mp/PoWehJ). – j0k Dec 28 '12 at 09:41
  • 1
    Can you connect via command line from your server? mysql -utinfanide -pMyPassword -hSQL09.FREEMYSQL.NET tinfanide – m4t1t0 Dec 28 '12 at 09:43
  • @Charles Right. Forgotten to include the actual error: "Warning: mysql_connect() [function.mysql-connect]: Can't connect to MySQL server on 'SQL09.FREEMYSQL.NET' (4) in /home/vol13/xtreemhost.com/xth_9595110/htdocs/RemoteSQLTest.php on line 8". Can't connect to MySQL server on 'SQL09.FREEMYSQL.NET' (4) – Tin Amaranth Dec 28 '12 at 11:40
  • 1
    ... *`(4)`*? Really? Do you get the same error when you use the IP? Have you checked with your host to make sure they allow *outgoing* connections on port 3306? – Charles Dec 28 '12 at 11:46
  • @m4t1t0 I don't have the command line control for FreeMySQL.net (I cannot do so by going to the CMD on my local machine). Normally, I create tables or do things for the database by going to FreeMySQL.net on my browser where I execute SQL commands. – Tin Amaranth Dec 28 '12 at 12:01
  • @Charles Did you mean an IP of my SQL database on FreeMySQL.net? Even I did: $server = "208.11.220.xxx" (the IP I saw on my browser when I logged in to my SQL database), the same error threw. – Tin Amaranth Dec 28 '12 at 12:04
  • @Charles I've sent an email to ask the provider FreeMySQL.net if they support remote access (I suppose it is what you meant by "allow outgoing connections on port 3306"). They have not yet replied. – Tin Amaranth Dec 28 '12 at 12:07
  • @TinAmaranth, I meant the *host running the script* needs to be asked that question. They could be blocking outgoing connections on 3306, which is what the other server would be listening on. – Charles Dec 28 '12 at 18:13
  • @All All clear after I've found a MySQL server that supports remote connection. The problem with 3306 or connecting via command line as the crux of my query is I didn't have a server that allows external connection so I came here to ask. Anyway, your info teaches me more about SQL. – Tin Amaranth Dec 30 '12 at 06:47

1 Answers1

0

The crux of the problem of mine is that I thought I had a SQL server which allows external connection but actually not. Now I've applied for a SQL server that supports the feature and the problem with the PHP script is resolved.

Tin Amaranth
  • 683
  • 2
  • 12
  • 23