php代码
<?php // 根据uid进行分库分表 $uid = 10; $model = UserContact::model($uid); // 覆盖了原有参数,改为传人分库分表所依据的值 $data = $model->findAll(); $data = $model->dbConnection->createCommand() ->select("*") ->from($model->tableName()) ->where('uid>1') ->limit(10) ->queryAll(); $db = Yii::app()->dbConnectionManager->sharded($uid); // 调用sharded方法 设置库和表 $data = $db->createCommand() ->select("*") ->from('user_contact_'.$db->shardedTableKey) ->where('uid>1') ->limit(10) ->queryAll();