我将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中测试一下,我成功地连接了数据库和所有(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));
当我尝试登录时收到消息:
状态[42S02]:
[Microsoft][用于SQL Server的ODBC驱动程序17][SQL Server]无效的“用户”对象名称。(SQL:从[用户]中选择前1个 *,其中[电子邮件] =管理员且[用户].[删除时间]为空)”
我想雄辩必须在所有查询中添加一个示例名称......我不知道该如何进行......?
也许,而不是
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
1条答案
按热度按时间bksxznpy1#
"我解决了我的问题"
我的问题是,当我在进行迁移时,我在模式Map级别上使用sql server migration assistant for mysql进行了错误配置。
我在sql server数据库中的所有表是:mysql数据库名称.数据表名称
解决方案
源架构:mysql数据库名称
目的模式:sqlsrv数据库名称.dbo
dbo是必需的
现在所有的表如下:dbo.表名