views:

65

answers:

4

I've been working on a website on my own xampp server on my computer with my own database and everything and so far it's been pretty smooth, surprisingly. Now I want to upload it to a host, and I found a free web host and I was able to upload the site through dreamweaver/ftp. I exported my DB into an SQL query and than ran that query on the live DB so that they would have the same data.

I'm curious, what's the best way to keep these DB's in sync?

1) In my header.php, I specify some connection variables for my local db and I have to make sure to change them when I upload header.php to the site so they have the correct connection variables for the remote db. Maybe if I had a file on my hosting server and a file on my local server that specified the connection information and just never messed with them?

2) If I change something in my local DB, I have to copy the SQL and run it in my remote one as well. Is there a good way to handle this?

Thanks again!

A: 

For #1, you can either do that--the route most people take--or make the config file check the IP before loading server specific configuration. If the IP is 127.0.0.1, you load your development configuration. If it is the IP of the host, it loads a different config.

I personally do not know of a better way to handle #2. So, this answer will have to be incomplete.

Fletcher Moore
A: 

http://www.databasejournal.com/features/mysql/article.php/3355201/Database-Replication-in-MySQL.htm

I think he wants a development DB and a production DB, which replication may not help with since if you broke something in the development DB it would nuke production as well...
ircmaxell
for #2) if you are talking about changing database data and structure of your developer machine then you can make a sql file. The file would be a sql file, you need to run that file on live server to take the changes in effect
he said he want it sync'd
http://articles.sitepoint.com/article/mysql-data-sqlyog-job-agent
I'm reading over some of these articles now to see if they're helpful. Has anyone had any experience with dreamweaver? Is there a way to mark a file as local only, so that it doesn't get "PUT" to the remote server?
JPC
@user295189 awesome site, very helpful
JPC
A: 
  1. I usually keep the template stuff separate from the db connection, global variable stuff, and session stuff with an include file like 'init.php' or 'config.php'. When you update your stuff, most likely you won't need to overwrite that file.

  2. I use linux, so I use 'mysqldump' to get a .sql file, upload to server, then just upload 'mysql -u user -p databasename < database.sql'. It would be great if there was a quicker way that I don't know of.

russjman
A: 

1: Yes, create a config.php file with the server-specific information and include it when you need it. This is incredibly common and normal. Ideally, you can keep this file a little separate from your other files so that it's easy to grab all of your application files and copy them to the live server without also copying the config file. Keep a backup of your live config file somewhere, because one day you will overwrite it, and it's much better for your heart if you don't have to scramble to figure out what the live database password was.

2: There are some automated ways of handling this, but they're very complicated. What I usually do is create an empty text file named changes.sql or something. As I make changes to the dev database, I paste the CREATE TABLE and ALTER TABLE, etc. queries into the changes.sql file. This way I have one file with all the changes I need to make to the live server when I'm ready to update the live site. After I do the update, I save the changes.sql file somewhere and create a new empty file for the next changes.

More 2: You can also just do a dump of the whole dev database and copy it live. Most sites, though, have data on the live server that should not be destroyed or copied to dev - user information, orders, login tracking, user comments, whatever. So you generally do no not want to just replace all your live data with dev data.

Scott Saunders