: 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.