How php operates mysql database simple table Sharding-detailed steps

Source: Internet
Author: User
: This article mainly introduces the principle of simple table sharding for mysql database operations with detailed steps. For more information about php tutorials, see.
 Query ("$ SQL"); //} // Create an id storage table. In fact, you do not have to call an id. if the business volume is large, you can use the id by year, month, or day, you can also use the incremental value. // Create table 'test '. 'create _ id' ('id' BIGINT (20) not null AUTO_INCREMENT primary key) ENGINE = MYISAM; // create a new table. do you need to know it yourself (use paging later, the query speed is very fast. if you do not want this table, use union to query it: Put all the table names in the array, then, foreach assembles the SQL statement. union. So it's better to do it at the beginning) // create table 'article _ total' (// 'id' bigint (20) not null, // 'subobject' varchar (200) not null, // 'content' text not null, // primary key ('id') //) ENGINE = MRG_MyISAM default charset = utf8 UNION = ('article _ 0 ', 'article _ 1', 'article _ 2', 'article _ 3'); // Query OK, 0 rows affectedfunction get_AI_ID () {global $ mysqli; $ mysqli-> query ('Insert into create_id (id) values ("") '); // return the insert id value return mysqli_insert_id ($ mysqli);} function new_article () {global $ mysqli; echo $ id = get_AI_ID (); echo $ table_name = get_table_name ($ id); $ SQL = "insert into {$ table_name} (id, subject, content) values ('{$ id}', 'title', 'Content') "; echo $ SQL; $ mysqli-> query ($ SQL);} function get_table_name ($ id) {return 'article _'. intval ($ id) % 10;} new_article ();

The above introduces the principle of simple table sharding for mysql database operations in php-detailed steps, including some content, and hope to help those who are interested in PHP tutorials.

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.