Пытаюсь запросить данные из таблицы prefix2_rooms:
Код: Выделить всё
Yii::app()->db->tablePrefix='prefix1_';
//$rcd=Rooms::model()->findByPk(1);
Yii::app()->db->tablePrefix='prefix2_';
$rcd=Rooms::model()->findByPk(11);
Настройки БД в main.php следующие:
Код: Выделить всё
...
'db'=>array(
'connectionString'=>'mysql:host=localhost;dbname=gb_db',
'username'=>'username',
'password'=>'password',
'charset'=>'utf8',
'tablePrefix'=>'sw_'
),
...
Код: Выделить всё
class Rooms extends CActiveRecord{
public static function model($className=__CLASS__){
return parent::model($className);
}
public function tableName(){
return '{{'.strtolower(get_class($this)).'}}';
}
public function beforeSave(){
if ($this->isNewRecord)
$this->prior=$this->maxPrior()+1;
return true;
}
public function maxPrior(){
return Yii::app()->db->createCommand()
->select('MAX(prior)')
->from($this->tableName())
->queryScalar();
}
public function relations(){
return array(
'periods'=>array(self::HAS_MANY, 'Periods', 'fk_room'),
'trans'=>array(self::HAS_ONE, 'Periods', 'fk_room', 'scopes'=>'trans'),
'before'=>array(self::HAS_ONE, 'Periods', 'fk_room', 'scopes'=>'before'),
'after'=>array(self::HAS_ONE, 'Periods', 'fk_room', 'scopes'=>'after'),
'inners'=>array(self::HAS_MANY, 'Periods', 'fk_room', 'scopes'=>'inners'),
'type'=>array(self::BELONGS_TO, 'Types', 'fk_type'),
'images'=>array(self::HAS_MANY, 'Images', 'fk_room', 'order'=>'images.prior ASC')
);
}
public function rules(){
return array(
array('fk_type, prior', 'numerical', 'integerOnly'=>true),
array('price', 'numerical'),
array('name', 'length', 'max'=>50),
array('is_off', 'boolean')
);
}
}