Repository navigation
need help in configuring #161
|
I want to split the database of multisite into 100 dbs, db00, db01, so on upto db99 .and when a new blog gets added to the multisite, the last two digits of the blog id go to a specified database, at the last two digits of the id. Examples: |
Replies: 1 comment
|
The last-two-digits scheme can be expressed directly with modulo. Register datasets named $wpdb->add_callback(
function ( $query, $wpdb ) {
$pattern = '/^' . preg_quote( $wpdb->base_prefix, '/' ) . '(\d+)_/';
if ( ! preg_match( $pattern, $wpdb->table, $matches ) ) {
return null;
}
$blog_id = (int) $matches[1];
return sprintf( 'db%02d', $blog_id % 100 );
}
);That maps blog 9 to Every dataset the callback can return must already be added with I have added this pattern, along with the migration cautions, to the wiki's Partitioning Recipes page. |
The last-two-digits scheme can be expressed directly with modulo. Register datasets named
db00throughdb99, then use a callback like this:That maps blog 9 to
db09, 74 todb74, 999989 todb89, and 9200 todb00. Returningnullleaves network-global tables on the default dataset.Every dataset the callback can return must already be added with
$wpdb->add_database(), and every site's complete table set must…