![]() |
PHP/Mysql Multiple Questions
Scenario: I have two databases located on two different servers. There are two options for the databases. 1. They contain a set of tables that are not in the other, but there would need to be a way to join those tables in queries. For example, database1 would contain tables a,b,c while database2 would have tables d,e,f. 2. They both are exact mirrors of each other with the same tables and data, but there would need to be a way to syncronize the data between the two. ie. (both databases have a,b,c,d,e,f tables)
1. How do you handle multiple mysql server connections on a single script/page? Is it even possible without having to use a "database.table.field" type queries? I would like to be able to open 2 connections to different databases located on different servers, then using joins on tables from both of them. Is that possible? 2. The two mysql servers can't be configured for Replication from Master to Slave. Is there a way to do replication type functionality with PHP? How would you compare 2 Mysql tables with PHP? What would be the simplest way? |
Re: PHP/Mysql Multiple Questions
1) I don't have a 100% positive answer but I don't think this is possible since each SQL statement is executed in the context of the opened db connection pointer. Sure you can have multiple pointers open to different DB servers but I don't believe there is a way to join these two pointers in an INNER JOIN/LEFT JOIN style syntax. I believe you'd have to do recordset enumeration in PHP and possibly some additional nested queries.
2) How many records? I guess you could use two arrays and compare them, inserting objects not found in array1 to db2 and array2 to db1. |
Re: PHP/Mysql Multiple Questions
Quote:
2. The tables in question are around 100 rows with about 4-10 fields. I'm thinking about making a change log table to record which tables were changed, then using that information to select the changed table/s and copying all those rows to the other table/s after those tables are emptied. I'm pondering this because the data in the tables can be deleted, new data be added, or the data could also be edited. And the extra logic needed to take these into account is something I don't quite have the time to develop. The tables in question aren't very large now, but I do expect them to grow larger in the future. By then though, I'm hoping we'll have moved on to servers that do allow Mysql replication which will make things much simpler. |
Re: PHP/Mysql Multiple Questions
Could you do something like this?
Code:
<?php |
Re: PHP/Mysql Multiple Questions
Quote:
I'm using php5 objects and global defines to make the connection to both databases. The base parent object contains the connect/select_db functions which gets inherited by all other objects which need to connect to the 2 databases to make queries. Pretty much all queries are done in sub classes. I actually ended up with more simpler queries than less complex large queries, but this seems to work to my advantage. ;) |
Re: PHP/Mysql Multiple Questions
Are you using ?
Code:
class foo { }Code:
class bar extends foo { } |
Re: PHP/Mysql Multiple Questions
Quote:
|
| All times are GMT -5. The time now is 08:59 PM. |
Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Copyright ©1998 - 2013, nV News.