PHP code example of mix / sharding-query

1. Go to this page and download the library: Download mix/sharding-query library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mix / sharding-query example snippets


$query = new \ShardingQuery\Query([
    'query'    => function ($sql) {
        return \think\Db::query($sql);
    },
    'table'    => [
        'order',
        'order_201805',
        'order_201804',
    ],
    'field'    => '{table}.*, u.name',
    'leftJoin' => [
        'user AS u ON u.member_id = {table}.member_id',
    ],
    'where'    => '{table}.member_id = 10001 AND status = 1',
    'order'    => '{table}.add_time DESC',
    'offset'   => 0,
    'limit'    => 10,
]);
// 查询结果
$result        = $query->select();
// 总行数,用于分页
$count         = $query->count();
// 追踪数据,用于调试
$trace         = $query->trace();