[Original] build support for Master / Slave read and write from the operation of the database category

  For larger than normal visit the website, the adoption of the basic MySQL Master / Slave structure is quite normal, but are generally a Master, Slave of more than one, but in general the time to visit this issue more, because Reading Write to be isolated, so today she is constructed on the operation of the database category. 

  Operation of the database category basic characteristics: 
  1. To support a Master, Slave Across the conditions, all SQL can be forced to deal with the call Master 
  2. Automatic Identification is able to read or write operation, then automatically connected to the needs of the Master / Slave server.    In the course of operation can automatically identify, if there is no Slave, all operations are at the Master's, if the current work of connecting the Slave is not automatically connected to other Slave.    For Slave read data using randomly selected Slave server way to read data 
  3. PHP in the same process can reuse connections, to link the database will not repeat, because of repeated connections to reduce the consumption of resources 

  1. Slave is to take the random selection Slave to read data, it is not true sense of the load balancing 
  2. Initialization are each connected for all the database, compared to waste resources and time to connect.    PHP in a number of procedures can not be maintained in the database connection, each time you start all need to connect to remote database and waste a lot of connecting the processing time, but this is PHP script with the relevant procedures. 
  3. Can not support a number of Master of the situation, and can be customized and relatively poor, many things are fixed, in accordance with the existing model to the implementation of enquiries 

  Notes code is not very full, some of the Notes and do not necessarily correct, so if their own use, preferably twice amended. 
  This category made reference to the database before I wrote the "simple and rapid operation of the MySQL database interesting category: SimpleDB",照着can see. 
  (Class of interfaces I have been most of the tests are normal, normal or if they do not have a better idea, please post) 

  Document: db_common.class.php 

  <? php 
  //———————————————— —- 
  / / Master / Slave database to read and write separate operation category 
  / / 
  / / Author: heiyeluren <? PostId = 1716041 

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google
  • DZone
  • Netvouz
  • NewsVine
  • Technorati

You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

AddThis Social Bookmark Button