danesc Posted May 4, 2009 Share Posted May 4, 2009 Guys, I have two MySQL servers 5.0.77-log on different machines. One is the "master" and the other one is the "slave" with a replication happening real-time. Here is my question: How do I configure my PHP scripts to use the Master for INSERT, UPDATE and the Slave for all SELECT statements? My current configuration is setup to do all MySQL interactions with one server (Master) but now I want to separate the two. Here is my current configuration... please help out with what the new configuration would be: $database = "some_db_name"; $user = "some_username_here"; $pass = "some_password_here"; $host = "xx.xx.xx.xx"; $connection = mysql_connect( $host, $user, $pass ) or failed_connection( mysql_error() ); mysql_select_db( $database ) or failed_connection( mysql_error() ); Thank you in advance! Quote Link to comment https://forums.phpfreaks.com/topic/156864-mysql-php-write-read-servers-separate/ Share on other sites More sharing options...
Ken2k7 Posted May 4, 2009 Share Posted May 4, 2009 Well I guess you can check for the first word in a SQL and choose the correct connection. Though I would restrict in the member to have only the permissions on master and slave respectively so they don't accidentally do something you don't want. Quote Link to comment https://forums.phpfreaks.com/topic/156864-mysql-php-write-read-servers-separate/#findComment-826303 Share on other sites More sharing options...
danesc Posted May 5, 2009 Author Share Posted May 5, 2009 I'm looking into using mysql-proxy ... any one uses this? thoughts? Things to lookout for? Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/156864-mysql-php-write-read-servers-separate/#findComment-826681 Share on other sites More sharing options...
fenway Posted May 5, 2009 Share Posted May 5, 2009 What's wrong with a db abstraction layer? Quote Link to comment https://forums.phpfreaks.com/topic/156864-mysql-php-write-read-servers-separate/#findComment-826750 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.