在 yii2 中,我必須將整個(gè)表從一個(gè)數(shù)據(jù)庫(kù)復(fù)制到另一個(gè)數(shù)據(jù)庫(kù)為此,我使用了以下代碼,但出現(xiàn)了錯(cuò)誤:$dbName = "db1";$table = "demotable";$liveDbName = "db2";$command3 = $connection->createCommand('CREATE TABLE `'.$dbName.'.'.$table.'` SELECT * FROM `'.$liveDbName.'.'.$table.'`');$command3->execute();但出現(xiàn)如下錯(cuò)誤: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貢獻(xiàn)1810條經(jīng)驗(yàn) 獲得超4個(gè)贊
如果要指定帶有表的數(shù)據(jù)庫(kù),則應(yīng)該有兩個(gè)不同的字符串并用點(diǎn)分隔。`database`.`table`。
在您的代碼中將 `'.$dbName.'.'.$table.'`返回統(tǒng)一的字符串`db1.demotable`。所以 SQL 試圖找到一個(gè)名為“db1.demotable”的表。第二個(gè)表也有同樣的問(wèn)題。
嘗試使用此代碼:
$dbName = "db1";
$table = "demotable";
$liveDbName = "db2";
$command3 = $connection->createCommand("CREATE TABLE `$dbName`.`$table` SELECT * FROM `$liveDbName`.`$table`");
$command3->execute();
- 1 回答
- 0 關(guān)注
- 149 瀏覽
添加回答
舉報(bào)
0/150
提交
取消