chaiwei Posted January 19, 2010 Share Posted January 19, 2010 Hi, I want to have mysql sync between two same application different host using same databases. So I need to create two connection in php? Ok , example, server A and server B So if I want to sync FROM A to B So I drop all the table in B first, then create the new table in B then select * table from server A using php and INSERT INTO server B ? or I create a sql file from server A after that using import into server B is more efficient? Quote Link to comment https://forums.phpfreaks.com/topic/188990-mysql-sync/ Share on other sites More sharing options...
trq Posted January 19, 2010 Share Posted January 19, 2010 Sorry, but the description of what you want to do is not at all clear. Do you want to simply use one database with two applications? Quote Link to comment https://forums.phpfreaks.com/topic/188990-mysql-sync/#findComment-997851 Share on other sites More sharing options...
chaiwei Posted January 19, 2010 Author Share Posted January 19, 2010 oops, sorry.. I have a live application and database in SERVER A, then my boss want to use the application even offline (without internet), So I need to install xampp in his computer, then I need to create a button that let him press once and the live database will pump inside the xampp database. Normally I can use phpmyadmin to export into a sql file, and then use pendrive and copy to my boss pc, and import again. but he don't want like this, what he want is create a button and once press, the application will look up the live database, and insert in his own pc database, so his pc will have the latest updated data. I only can come with the idea is create a script and with two connection, $conn = mysql_connect('192.168.2.4' , xxx,xxx) $conn1 = mysql_connect('192.168.2.5', xxx, xxx) SELECT * FROM -> using $conn while(xxx xxx){ INSERT INTO -> using $conn1 } but if the database is large, then the process will take very long time to complete. right? So I wonder whether the above example will slower compare to use phpmyadmin to export and then import again? if that any other ways to complete this? Quote Link to comment https://forums.phpfreaks.com/topic/188990-mysql-sync/#findComment-997854 Share on other sites More sharing options...
chaiwei Posted January 19, 2010 Author Share Posted January 19, 2010 I stuck at here. $sql = 'SHOW TABLES'; $result = $remote->query( $sql ); foreach($result->rows as $value){ $sql = 'SELECT * FROM '. $value['Tables_in_commerce'].'<br />'; $local->query('Create TABLE '. $value['Tables_in_commerce']); } Create table xxx xxx How I gonna get the field name, field type, primary key, collaction and put in the create table syntax? Quote Link to comment https://forums.phpfreaks.com/topic/188990-mysql-sync/#findComment-997929 Share on other sites More sharing options...
chaiwei Posted January 19, 2010 Author Share Posted January 19, 2010 Ok, Found it.. Using mysql_query('SHOW CREATE TABLE tablename'); references http://dev.mysql.com/doc/refman/5.0/en/show-create-table.html Quote Link to comment https://forums.phpfreaks.com/topic/188990-mysql-sync/#findComment-997950 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.