0

I have a php+mysql application and would like to know what's the best way to make my app work when the internet connection is lost.

I thought of having two identical DataBases, one in my internet host, and other in my localhost. So, when there is no connection, I would store all the data to my localhost.

My question is how can I transfer the data from my localhost to the DataBase in my internet host?

Renan Ferreira
  • 2,122
  • 3
  • 21
  • 30
  • What does your application do? – shapeshifter Mar 08 '13 at 03:53
  • [Possibly Duplicate](http://stackoverflow.com/questions/1935314/connecting-to-remote-mysql-server-using-php).Are you trying to connect the mysql remote server ? if you would like to access the remote server [refer here](http://support.hostgator.com/articles/cpanel/how-to-connect-to-the-mysql-database) @Renan Lopes Ferreira – thar45 Mar 08 '13 at 03:54
  • I need the data to be in a remote server. But I would like a way to make my app work even when there is no connection to this remote server. – Renan Ferreira Mar 08 '13 at 03:59
  • recommendation is you should be in the network(LAN) both your local host and remote server so its possible ,, There isnt necessary to have an internet connections. – thar45 Mar 08 '13 at 04:05

3 Answers3

1

You need to use replication - this link will tell you how to set it up so that your local machine is a replica of the remote machine.

Ed Heal
  • 59,252
  • 17
  • 87
  • 127
  • This seems to be the best way, however, I don't have access to those ".ini" files on my remote server! – Renan Ferreira Mar 08 '13 at 11:22
  • Is your requirement to have a local copy just for testing purposes or for a copy to be up to date? – Ed Heal Mar 08 '13 at 11:28
  • I need the localhost to be a copy, but I like to all the changes made in the localhost, when the internet access is gone, to be transfered to the remote server. The internet in my Country is very instable, but I need the data to be there, and the system to work even when there is no connection. The remote server is the same one that host my website, so that's why a don't have permition to change those ".ini" files – Renan Ferreira Mar 08 '13 at 11:45
  • Why not write the local code to just produce the SQL statements and write those to a file. The write a script to periodically check if those scripts exists. If so try to apply them to the remote server and delete them if successful. Also periodically just update your local machine from the remote machine. The remote machine being the master copy and the local machine being the slave (i.e. not always up to date but you can live with that) – Ed Heal Mar 08 '13 at 11:51
  • Never thought about this! Thanks for the help. I will try this solution. – Renan Ferreira Mar 11 '13 at 13:06
  • 1
    Also I should add you should apply those scripts in chronological order (perhaps name them with a unix time stamp. – Ed Heal Mar 11 '13 at 15:54
1

Are you just collecting data like subscriptions? If so, you could just queue up new records temporarily when you detect that your main db is down, and do ordinary inserts and deletes to transfer the unprocessed new records when you detect that both databases are available and any unprocessed records exist locally.

If you need to query and maintain relational data between the two databases, then you'll need a more robust and complex replication strategy.

phatfingers
  • 9,770
  • 3
  • 30
  • 44
  • I thought about this, but there are to many tables, and many operations. Knowing where the update has occured and transfer it, one by one, to the remote server doesn't seem to be the best way – Renan Ferreira Mar 08 '13 at 11:18
  • It sounds like you need multi-master replication, which is a challenging problem. There's a decent-looking blog discussion with references to a Galera Cluster and XtraDB Cluster here: http://www.mirantis.com/blog/ha-platform-components-mysql-rabbitmq/ – phatfingers Mar 08 '13 at 15:09
-1

If you have phpMyAdmin on both servers you can export the localhost database and then import it on the hosted database.

PriestVallon
  • 1,519
  • 1
  • 22
  • 44