在 yii2 中,我必須將整個表從一個數據庫復制到另一個數據庫為此,我使用了以下代碼,但出現了錯誤:$dbName = "db1";$table = "demotable";$liveDbName = "db2";$command3 = $connection->createCommand('CREATE TABLE `'.$dbName.'.'.$table.'` SELECT * FROM `'.$liveDbName.'.'.$table.'`');$command3->execute();但出現如下錯誤:Database Exception – yii\db\ExceptionSQLSTATE[42S02]: Base table or view not found: 1146 Table 'db1.db2.demotable' doesnt existThe SQL being executed was: CREATE TABLE `db1.demotable` SELECT * FROM `db2.demotable`Error Info: Array( [0] => 42S02 [1] => 1146 [2] => Table 'db1.db2.demotable' doesnt exist)
1 回答

蝴蝶不菲
TA貢獻1810條經驗 獲得超4個贊
如果要指定帶有表的數據庫,則應該有兩個不同的字符串并用點分隔。`database`.`table`。
在您的代碼中將 `'.$dbName.'.'.$table.'`返回統一的字符串`db1.demotable`。所以 SQL 試圖找到一個名為“db1.demotable”的表。第二個表也有同樣的問題。
嘗試使用此代碼:
$dbName = "db1";
$table = "demotable";
$liveDbName = "db2";
$command3 = $connection->createCommand("CREATE TABLE `$dbName`.`$table` SELECT * FROM `$liveDbName`.`$table`");
$command3->execute();
- 1 回答
- 0 關注
- 152 瀏覽
添加回答
舉報
0/150
提交
取消