How does symfony2doctrine split databases and tables?

Source: Internet
Author: User
As database tables grow bigger, you want to consider table sharding. I am using symfony2, so I would like to ask, how does symfony2 split databases and tables... As database tables grow bigger, you want to consider table sharding. I am using symfony2, so I would like to ask, how does symfony2 split databases and tables...

Reply content:

As database tables grow bigger, you want to consider table sharding. I am using symfony2, so I would like to ask, how does symfony2 split databases and tables...

Let's start with the following:

If the database supports (such as MySQL or PostgreSQL), we recommend that you directly use the database's partitioning. if you cannot solve your needs, you can:

Use event listening to modify or dynamically register database connection instances based on the user ID or other Database Sharding conditions.

Or simply, register multiple connected instances and define a helper for the desired instance, for example, Database Sharding by user ID:

// (1) in app/config. yml: # define the connection of each database // (2) in the controller: private function getManager () {$ user = $ this-> getUser (); // get the current user $ shardId = null! ==$ User? $ User-> getId () % 4: 0; // 0, 1, 2, 3 A total of four libraries return $ this-> getDoctrine () -> getManager (sprintf ('Shard _ % s', $ shardId);} // (3) in Business Action: public function someAction () {$ om = $ this-> getManager (); // The current user's database is connected to the instance //...}

In your business code, you have to consider the integrity of your business after partitioning.

Different from traditional

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.