Yii 关于AR分表
2019独角兽企业重金招聘Python工程师标准>>>
<?php
/**
* This is the model class for table "t_user".
*
* The followings are the available columns in table 't_user':
* @property string $userid
* @property string $id
* @property string $withdraw
* @property string $amount
* @property string $ctime
*/
class CollectRecord extends CActiveRecord
{
/**
* @return string the associated database table name
*/
public function tableName()//主要是对tableName进行改进
{
$date = time();
$tablename = $this->getTableName($date);
return $tablename;
}
private function getTableName($date){
$time = intval($date) + 28800;//为何+28800自己琢磨下就知道了
$tableend = floor($time/604800);//每周进行一次表的维护新建
$tableName = __CLASS__.'_'.$tableend;
$sql='SHOW FULL COLUMNS FROM '.$tableName;
try
{
$tableExist=!!($this->getDbConnection()->createCommand($sql)->queryAll());
}
catch(Exception $e)
{
$tableExist= false;
}
if(!$tableExist){
try {
$db = $this->getDbConnection();
$db->createCommand()->createTable($tableName, array(
'id' => 'pk',
'withdraw' => 'tinyint(1)',//true is Deposits false is withdrawals;
'amount' => 'decimal(20,4)',
'userid' => 'int(11)',
'ctime' => 'int(11)',
));
}catch (\yii\db\Exception $exc){
return false;
}
}
return $tableName;
}
/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('withdraw,amount,cuserid', 'required'),
array('cuserid,ctime', 'numerical', 'integerOnly'=>true),
array('userid, ctime', 'length', 'max'=>11),
array('amount', 'length', 'max'=>20),
array('withdraw', 'length', 'max'=>4),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('userid, amount, withdraw, ctime,id', 'safe', 'on'=>'search'),
);
}
/**
* @return array relational rules.
*/
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'id' => 'Id',
'withdraw' => 'Withdraw Or Deposit',
'amount' => 'Amount',
'userid' => 'User',
'ctime' => 'Create Time',
);
}
/**
* Retrieves a list of models based on the current search/filter conditions.
*
* Typical usecase:
* - Initialize the model fields with values from filter form.
* - Execute this method to get CActiveDataProvider instance which will filter
* models according to data in model fields.
* - Pass data provider to CGridView, CListView or any similar widget.
*
* @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
*/
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('userid',$this->userid,true);
$criteria->compare('amount',$this->amount,true);
$criteria->compare('id',$this->id,true);
$criteria->compare('withdraw',$this->withdraw,true);
$criteria->compare('ctime',$this->ctime,true);
return new CActiveDataProvider($this->tableName(), array(
'criteria'=>$criteria,
));
}
/**
* Returns the static model of the specified AR class.
* @return t_user the static model class
*/
public static function model($className=__CLASS__)
{
return parent::model($className);
}
}
转载于:https://my.oschina.net/yonghan/blog/533061
Yii 关于AR分表相关推荐
- php 操作分表代码
//哈希分表function get_hash_table($table, $userid) {$str = crc32($userid);if ($str < 0) {$hash = &quo ...
- 分库分表之后,主键的处理方法
面试题 分库分表之后,id 主键如何处理? 面试官心理分析 其实这是分库分表之后你必然要面对的一个问题,就是 id 咋生成?因为要是分成多个表之后,每个表都是从 1 开始累加,那肯定不对啊,需要一个全 ...
- ShardingSphere-Proxy分库分表以及多租户安装使用
需求:你提供SAAS服务,你有你有2个租户(商户),各自的数据进各自的库,而你不希望你的微服务java里默认配置多个租户数据源,数据连接池太多,而且后面动态增加也不方便,诸如此类很多问题. 方案:Sh ...
- mysql 分表原理_MYSQL 分表原理(转)
简介: 引用MySQL官方文档中的一段话:MERGE存储引擎,也被认识为MRG_MyISAM引擎,是一个相同的可以被当作一个来用的MyISAM表的集合."相同"意味着所有表同样的列 ...
- mysql如何根据业务分表设计_mysql分表分库的应用场景和设计方式
很多朋友在论坛和留言区域问mysql在什么情况下才需要进行分库分表,以及采用何种设计方式才是最优的选择,根据这些问题,小编为大家整理了关于MySQL分库分表的应用场景和最优的设计方式举例. 一. 分表 ...
- 从原则、方案、策略及难点阐述分库分表
版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/qq_34173549/article/details/79936693 一.分库分表原则 关系型数据 ...
- 分表分库之一:分布式数据库的常见用法
尽量减少事务边界 采用分库分表的方式将业务数据拆分后,如果每条SQL语句中都能带有分库分表键,分布式服务层对于SQL解析后都能精准地将这条SQL语句推送到该数据所在的数据库上执行,数据库将执行的结果再 ...
- 一种可以避免数据迁移的分库分表scale-out扩容方式
原文地址:http://jm-blog.aliapp.com/?p=590 目前绝大多数应用采取的两种分库分表规则 mod方式 dayofweek系列日期方式(所有星期1的数据在一个库/表,或所有?月 ...
- Mycat 读写分离 数据库分库分表 中间件 安装部署,及简单使用
MyCat是一个开源的分布式数据库系统,是一个实现了MySQL协议的服务器,前端用户可以把它看作是一个数据库代理,用MySQL客户端工具和命令行访问,而其后端可以用MySQL原生协议与多个MySQL服 ...
最新文章
- C++智能指针管理类
- Linux如何查找大文件或目录总结
- 记录贴-配置HTTPS域名访问到本地局域网网关
- dfs——练习demo3(20届周新杰提供)
- chrome开发总结(交互/权限/存储)-爬虫
- 深入理解InnoDB(4)—索引使用
- 分分钟甩Word几条街,Python编辑公式竟可以如此简单,赶紧收藏!!
- 6-3 十进制转二进制(顺序栈设计和应用) (8 分)
- git pull push 项目的时候总是提示要输入用户名密码的解决方案
- CSDN APP又出错了,看不到博文
- spring boot学生课程考试系统的设计与实现毕业设计源码171548
- Pytorch Tutorial 学习笔记(六)模型部署
- git 提交错误:The requested URL returned error: 502
- 【屏类型结构体定义PanelType】 文档位置:《apiPNL.h》
- USDP使用笔记(四)打通双集群HDFS实现跨nameservice访问
- CE-扫描扫雷中雷区地址
- Python图片处理模块PIL(pillow)
- radisys官方介绍--Promentum ATCA-1200== ATCA 可控 4-AMC 刀片式载板
- android 图库开发实例,Android中从图库中选取图片实例详解
- 用myeclipse打包项目时,Security alert:integrity check error。