'components' => [ 'db' => [ 'class' => 'yii\db\Connection', 'dsn' => 'mysql:host=10.10.10.10;port=4005;dbname=wordpress', 'username' => 'wp', 'password' => '123', 'charset' => 'utf8', ],
class ActiveRecord extends BaseActiveRecord {
/**
* Returns the database connection used by this AR class.
* By default, the "db" application component is used as the database connection.
* You may override this method if you want to use a different database connection.
* @return Connection the database connection used by this AR class.
*/
public static function getDb()
{
return Yii::$app->getDb();
}
abstract class Application extends Module {
/**
* Returns the database connection component.
* @return \yii\db\Connection the database connection.
*/
public function getDb()
{
return $this->get('db');
}
class OrderInfo extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
* @return
*/
public static function tableName()
{
return 'order_info';
}
class OrderInfo extends \yii\db\ActiveRecord
{
private static $partitionIndex_ = null; // 分表ID
/**
* 重置分区id
* @param unknown $uid
*/
private static function resetPartitionIndex($uid = null) {
$partitionCount = \Yii::$app->params['Order']['partitionCount'];
self::$partitionIndex_ = $uid % $partitionCount;
}
/**
* @inheritdoc
*/
public static function tableName()
{
return 'order_info' . self::$partitionIndex_;
}
class OrderInfo extends \yii\db\ActiveRecord {
private static $databaseIndex_ = null; // 分库ID
private static $partitionIndex_ = null; // 分表ID
/**
* 重置分区id
* @param unknown $uid
*/
private static function resetPartitionIndex($uid = null) {
$databaseCount = \Yii::$app->params['Order']['databaseCount'];
$partitionCount = \Yii::$app->params['Order']['partitionCount'];
// 先决定分到哪一张表里
self::$partitionIndex_ = $uid % $partitionCount;
// 再根据表的下标决定分到哪个库里
self::$databaseIndex_ = intval(self::$partitionIndex_ / ($partitionCount / $databaseCount));
}
/**
* @inheritdoc
*/
public static function tableName()
{
$database = 'wordpress' . self::$databaseIndex_;
$table = 'order_info' . self::$partitionIndex_;
return $database . '.' . $table;
}
'db0' => [ 'class' => 'yii\db\Connection', 'dsn' => 'mysql:host=10.10.10.10;port=6184;dbname=wordpress0', 'username' => 'wp', 'password' => '123', 'charset' => 'utf8', // 'tablePrefix' => 'ktv_', ], 'db1' => [ 'class' => 'yii\db\Connection', 'dsn' => 'mysql:host=10.10.10.11;port=6184;dbname=wordpress2', 'username' => 'wp', 'password' => '123', 'charset' => 'utf8', // 'tablePrefix' => 'ktv_', ], 'db2' => [ 'class' => 'yii\db\Connection', 'dsn' => 'mysql:host=10.10.10.12;port=6184;dbname=wordpress4', 'username' => 'wp', 'password' => '123', 'charset' => 'utf8', // 'tablePrefix' => 'ktv_', ], 'db3' => [ 'class' => 'yii\db\Connection', 'dsn' => 'mysql:host=10.10.10.13;port=6184;dbname=wordpress6', 'username' => 'wp', 'password' => '123', 'charset' => 'utf8', // 'tablePrefix' => 'ktv_', ],
class OrderInfo extends \yii\db\ActiveRecord
{
private static $databaseIndex_ = null; // 分库ID
private static $partitionIndex_ = null; // 分表ID
/**
* 重置分区id
* @param unknown $uid
*/
private static function resetPartitionIndex($uid = null) {
$databaseCount = \Yii::$app->params['Order']['databaseCount'];
$partitionCount = \Yii::$app->params['Order']['partitionCount'];
// 先决定分到哪一张表里
self::$partitionIndex_ = $uid % $partitionCount;
// 再根据表的下标决定分到哪个库里
self::$databaseIndex_ = intval(self::$partitionIndex_ / ($partitionCount / $databaseCount));
}
/**
* 根据分库分表,返回库名.表名
*/
public static function tableName()
{
$database = 'wordpress' . self::$databaseIndex_;
$table = 'order_info' . self::$partitionIndex_;
return $database . '.' . $table;
}
/**
* 根据分库结果,返回不同的数据库连接
*/
public static function getDb()
{
return \Yii::$app->get('db' . self::$databaseIndex_);
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有