"SQLSTATE[42S02]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server] 对象名称无效'users'



我将MySQL数据库迁移到SQL Server 2019.

我做了所需的配置:

php.ini
extension=php_pdo_sqlsrv_80_ts_x64
extension=php_sqlsrv_80_ts_x64
.env
DB_CONNECTION=sqlsrv
DB_HOST=servername
DB_PORT=null
DB_DATABASE=dbname
DB_USERNAME=sa
DB_PASSWORD=password

下面的代码运行良好。在web.php中测试,我得到db连接成功,所有(2)表。

try {
DB::connection()->getPdo();
echo DB::connection()->getDatabaseName()."  db connect successfully";
} catch (Exception $e) {
dd($e->getMessage());
}
$sql = DB::select("SELECT  TOP (2) id, email, email_verified_at, password, remember_token, image, userable_id, userable_type, created_at, updated_at, deleted_at FROM soraeir.users", [1]);
die(print_r($sql));

消息当我尝试登录我得到:

SQLSTATE[42S02]:
[Microsoft][ODBC Driver 17 for SQL Server][SQL Server]无效的"users"对象名称。(SQL: select top 1 * from [users] where [email] = admin and [users].)[deleted_at] is null)"

我认为雄辩必须添加一个instance_name到所有的查询…我不知道如何继续…?

也许,而不是

select top 1 *
from [users]
where [email] = admin
and [users].[deleted_at] is null

我们可以用

select top 1 * 
from [instance_name].[users]
where [email] = admin
and [users].[deleted_at] is null

问题解决了

我的问题是当我做迁移时,我错误地配置了mysql的sql server迁移助手的模式映射级别.

mysql server db中的所有表:mysql_db_name.table_name

<解决方案/strong>

源模式: mysql_db_name

目标模式: sqlsrv_db_name。dbo

dbo需要

现在所有的表如下所示:

相关内容

  • 没有找到相关文章

最新更新