语法错误或访问冲突:1327 Undeclared变量:

时间:2017-12-04 11:14:20

标签: php laravel-5

为什么我会收到此错误

Syntax error or access violation: 1327
Undeclared variable: database1 (SQL: SELECT * INTO `database1`.dbo.`tablename` FROM `database2`.dbo.`tablename`

在同一台服务器上复制数据库时?

1 个答案:

答案 0 :(得分:0)

$newdatabase = 'newdatabase';
$tablename = 'users';
$olddatabase= 'existingdatabase';``
$results = DB::unprepared("CREATE TABLE $newdatabase.$tablename LIKE $olddatabase.$tablename") ;
 $sql = "INSERT INTO `$newdatabase`.`$tablename` SELECT * from `$olddatabase`.`$tablename`";
 $data = DB::insert($sql);