insert mysql query in localserver and webserver at the same time

0 views
Skip to first unread message

Cesar Ramos

unread,
Sep 8, 2010, 9:56:31 PM9/8/10
to Professi...@googlegroups.com
i have an app that it´s going to run on a local server and on a web server it´s there a way to store the same mysql query on both servers at the same time?

Cesar Ramos

unread,
Sep 9, 2010, 12:15:10 PM9/9/10
to Professi...@googlegroups.com

Jack Timmons

unread,
Sep 9, 2010, 12:18:10 PM9/9/10
to professi...@googlegroups.com

Sure.

$query = "SELECT * FROM mytable";

--
Jack Timmons
@_Codeacula

Cesar Ramos

unread,
Sep 9, 2010, 12:23:32 PM9/9/10
to professi...@googlegroups.com
maybe it wasn´t completely clear, here´s the thing

we have two servers one local and another web

so the form must do a query to two connections one connection thats of the local server and another conection thats from the web server also the idea it´s to have the two databases sincronized.



--
This group is managed and maintained by the development staff at 360 PSG. An enterprise application development company utilizing open-source technologies for todays small-to-medium size businesses.

For information or project assistance please visit :
http://www.360psg.com

You received this message because you are subscribed to the Google Groups "Professional PHP Developers" group.
To post to this group, send email to Professi...@googlegroups.com
To unsubscribe from this group, send email to Professional-P...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/Professional-PHP

Robert Gonzalez

unread,
Sep 9, 2010, 12:53:35 PM9/9/10
to professi...@googlegroups.com
Sounds like you're crossing into the realm of replication...

Why are you hitting two different database in a live environment? Do the two have to stay synced up for all writes and reads? Making it happen is not that hard but you are going to have some pretty expensive code in that you are opening up two database connections, one over a network, for every process you handle. Nevermind the issues with latency or network failures (which do not affect localhost connections).

Just thinking out loud here, but it seems like this design might be able to be improved.

Cesar Ramos

unread,
Sep 9, 2010, 1:07:29 PM9/9/10
to professi...@googlegroups.com
well basically it will work as a backup the applicattion was originally built to work on web but they are saying in case that they don´t have an internet connection they can store the data locally and then sync with the web server also the idea of having a web server with the data synched it´s that they can  generate reports "in real time" and in case they don´t have internet connection they don´t loose data

Robert Gonzalez

unread,
Sep 9, 2010, 1:15:26 PM9/9/10
to professi...@googlegroups.com
If their data changes that fast that they need to have their information at the ready even if the internet drops you may want to consider setting them up with their own server located on their premises. I did that for a real estate customer of mine who have hundreds of concurrent writes throughout the day and server their local office as well as field agents. That is about the only way you can ensure that their data will always be what they need it to be.

Otherwise I'd recommend setting up a replicated environment for them, with one server located on site and the other located off site. Set their onsite database as the master and the off site as the slave and send writes from the master to the slave at whatever intervals you see fit.

Jack Timmons

unread,
Sep 9, 2010, 1:18:14 PM9/9/10
to professi...@googlegroups.com
On Thu, Sep 9, 2010 at 12:15 PM, Robert Gonzalez
<robert.anth...@gmail.com> wrote:
> If their data changes that fast that they need to have their information at
> the ready even if the internet drops you may want to consider setting them
> up with their own server located on their premises. I did that for a real
> estate customer of mine who have hundreds of concurrent writes throughout
> the day and server their local office as well as field agents. That is about
> the only way you can ensure that their data will always be what they need it
> to be.
> Otherwise I'd recommend setting up a replicated environment for them, with
> one server located on site and the other located off site. Set their onsite
> database as the master and the off site as the slave and send writes from
> the master to the slave at whatever intervals you see fit.

For the lazy, they could modify their scripts to write to both places
throughout execution. Provided they're using a class/interface for
their queries, etc.

--
Jack Timmons
@_Codeacula

Robert Gonzalez

unread,
Sep 9, 2010, 1:21:03 PM9/9/10
to professi...@googlegroups.com
True, but there would also need to be some type of logger implemented to keep track of writes from the network server that failed so that syncing could be done later in an intelligent manner. And other such things.

Jack Timmons
@_Codeacula

Cesar Ramos

unread,
Sep 9, 2010, 1:44:07 PM9/9/10
to professi...@googlegroups.com
well it´s goign to be setup the next way they currently will have 3 machines configured with windows apache mysql and php and those 3 machines should backup or sync or update 3 database that will be working on a vps so for example the vps would have configured 3 independent databases so thats like the setup that i will be aproaching

another thing it´s the app wich it´s currently made to store on a webserver or on a localhost but not to replicate or store at the same time on both servers so in this case what do you suggest that i do to the app?




On Thu, Sep 9, 2010 at 12:15 PM, Robert Gonzalez <robert.anth...@gmail.com> wrote:

Robert Gonzalez

unread,
Sep 9, 2010, 2:21:09 PM9/9/10
to professi...@googlegroups.com
If you need replication, build the architecture to replicate. You'll probably need to set up a proxy server and some balancers to handle the toggling between master(s) and slave(s) and perhaps you'll even want to set up memcached to use between them.

You'll also more than likely want to set up jobs that handle the actual replication routines at whatever intervals you determine fits your business needs.
Reply all
Reply to author
Forward
0 new messages