0

I am trying to connect to my database which is hosted on 000webhost. I am connecting from SmartFoxServer, and they allow database connections. All you have to do is change some of the settings in the smartfoxserver xml file.

I have successfully managed to connect to my localhost mysql database using these settings.

 <databaseManager active="true"> <connectionString>jdbc:mysql://localhost:3306/db_name</connectionString> <userName>root</userName> <password></password> <testSql>SELECT id FROM users LIMIT 1</testSql> </databaseManager> 

But when I tried to connect to my external database which is hosted on 000webhost and looks like this:

enter image description here

Using these settings

<connectionString>jdbc:mysql://mysql2.000webhost.com/a5939459_data</connectionString> <userName>a5939459_user</userName> <password>censored</password> <testSql>SELECT id FROM users LIMIT 1</testSql> 

I get the following error...

Exception: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException Message: Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driv er has not received any packets from the server. Description: The DBManager Test SQL failed Please double check your SQL code and make sure that Database server is running. 

EDIT:

But when I run php files on my localhost and ask for database connection like this, it works

<?php $db_username = "a5939459_user"; $db_name = "a5939459_data"; $db_password = "censored"; $db_host = "mysql2.000webhost.com"; mysql_connect($db_host,$db_username, $db_password, $db_name); mysql_select_db($db_name) or die (mysql_error()); ?> 

3 Answers 3

0

It is a big security issue to open up a database/mysql port for external/Internet connections. So when they created your database, they will most likely assign a user to connect only from limited source IPs, mostly Internal IPs. You need to communicate with their support for information from which source IPs you are allowed to connect. As John mentioned, the mysql2.000webhost.com resolves to a private IP address, and that implies you are most likely allowed to connect to it from some other private IP, which you might connect to through VPN or other means.

mysql2.000webhost.com. 14189 IN A 10.1.1.102 
8
  • Plz look at the edit Commented Feb 22, 2013 at 15:34
  • Oh, I can connect through php files because they do not require port but jdbc requires port? Is that the reason? Commented Feb 22, 2013 at 15:50
  • yes for jdbc you will need the port number - jdbc:mysql://mysql2.000webhost.com:3306 Commented Feb 22, 2013 at 15:52
  • I tried with port number but I still get the same error. Do you know solution to this problem? What options do I have from here? Commented Feb 22, 2013 at 15:54
  • stackoverflow.com/questions/2839321/… Commented Feb 22, 2013 at 15:56
0

The MySQL host they give you has a 10. IP address, which is unroutable on the Internet. You can only connect to that host from the web host they provide, not from another host.

4
  • At the moment, my smartfox server is on my laptop, but at the end I am going to upload it to my remote server on amazon ec2. But my mysql database will be on webhost? Will it work? Commented Feb 22, 2013 at 15:26
  • I do not understand you fully, do you mean I can not access mysql database from anywhere else except from the files that are uploaded on the webhost? Commented Feb 22, 2013 at 15:29
  • No. Your EC2 instance will not be able to get to the mysql2.000webhost.com server to talk to the database. Only the 000webhost web server can talk to that database server. Commented Feb 22, 2013 at 15:29
  • Plz look at the edit. Commented Feb 22, 2013 at 15:35
0

As pointed by others, the problem was indeed that 000webhost does not allow remote connections to mysql databases.

http://www.freesqldatabase.com/

Ended up using this for my mysql databases. It is free. It is actually quite reliable and fast. Has free remote connections allowed. Has phpMyAdmin.

Not sure about the security though, but otherwise a great alternative.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.