Yii 읽기 및 쓰기 분리 테이블 라이브러리
1759 단어 읽기 및 쓰기 분리
호출
//AR
class User extends ActiveRecord
{
public $useDbName= 'passport';
//$this->dbWrite();
}
//$connection = $model->getDbConnection();
//DAO
$connection = Yii::app()->db->setDbName('passport');
$count = $connection->createCommand('SELECT COUNT(*) FROM film')->queryScalar();
$sql = 'SELECT film_id,title FROM film';
$dataProvider=new CSqlDataProvider($sql,array(
'db'=> $connection,
'totalItemCount'=>$count,
));
Yii::app()->db->getLastInsertID();
//Query Builder
$user = Yii::app()->db->setDbName('passport')->createCommand()
->select('id, username, profile')
->from('tbl_user u')
->join('tbl_profile p', 'u.id=p.user_id')
->where('id=:id', array(':id'=>$id))
->queryRow();
현재 사용 중인 마스터 라이브러리 구성 보기
Yii::app()->db->setDbName('passport');
//print_r(Yii::app()->getComponent('passport'));
분표AR
public function primaryKey()
{
return 'id';
}
private $tableName = "servicesmsremindrecord";
public function updateMeta($code)
{
$this->tableName = "service_sms_remind_record_".str_pad(($code%100), 2, '0', STR_PAD_LEFT);
$this->refreshMetaData();
return $this;
}
//TestUserDayHealth::model($code)->with('user')->findAll();