我有Yii应用程序(Yii ver 1.xx),我需要连接2个DB。它从DB1获取数据并将其写入DB2。
以下是我在main.php中的连接
'db'=>array(
'class'=>'CDbConnection',
'connectionString' => 'mysql:host=localhost;dbname=db1',
'emulatePrepare' => true,
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'schemaCachingDuration'=>3600,
),
'db2'=>array(
'class'=>'CDbConnection',
'connectionString' => 'mysql:host=localhost;dbname=db2',
'emulatePrepare' => true,
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'schemaCachingDuration'=>3600,
),
基于'db2'中的数据,我需要将其写入'db'。以下是我编写查询的方式:
$view_tbl = 'CREATE OR REPLACE VIEW db.tableName AS ';
$view_tbl .= 'SELECT cl.client_id, cl.name
FROM clients cl
LEFT OUTER JOIN client_tob cl_tob ON cl_tob.client_id = cl.client_id
LEFT OUTER JOIN job_orders jo ON cl.client_id = jo.client_id
WHERE cl.status = 1
GROUP BY cl.client_id
ORDER BY cl.client_id DESC';
$query = Yii::app()->db2->createCommand($view_tbl);
$exec = $query->execute();
当我在本地运行查询时,查询会起作用。但是,当我尝试在服务器上运行它时,它给了我这个错误:
这是错的吗?是我打电话的方式&连接db是错误的吗?错误500
CDbCommand无法执行SQL语句:SQLSTATE [42000]:语法错误或访问冲突:1142 CREATE VIEW命令被拒绝 用户'db'@'localhost'用于表'tableName'