You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows7下Laravel执行migrate遇SQLSTATE[IMSSP]报错求助

Laravel 9连接SQL Server 2008执行php artisan migrate报错解决

环境信息

  • 操作系统:Windows 7 64位
  • 搭建环境:XAMPP
  • PHP版本:8.1.4
  • Laravel版本:9.29.0
  • 数据库:SQL Server 2008

报错详情

执行php artisan migrate时出现以下错误:

C:\xampp\htdocs\LaraUral>php artisan migrate

   Illuminate\Database\QueryException

  SQLSTATE[IMSSP]: This extension requires the Microsoft ODBC Driver for SQL Server to communicate with SQL Server. Access the following URL to download the ODBC Driver for SQL Server for x64: https://go.microsoft.com/fwlink/?LinkId=163712 (SQL: select * from sys.sysobjects where id = object_id(migrations) and xtype in  ('U', 'V'))

  at C:\xampp\htdocs\LaraUral\vendor\laravel\framework\src\Illuminate\Database\Connection.php:759
    755aЦХ         // If an exception occurs when attempting to run a query, we' ll format the error
    756aЦХ         // message to include the bindings with SQL, which will make this exception a
    757aЦХ         // lot more helpful to the developer instead of just the data base's errors.
    758aЦХ         catch (Exception $e) {   az? 759aЦХ             throw new QueryException(
    760aЦХ                 $query, $this->prepareBindings($bindings), $e
    761aЦХ             );
    762aЦХ         }
    763aЦХ     }

  1   C:\xampp\htdocs\LaraUral\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70
      PDOException::("SQLSTATE[IMSSP]: This extension requires the Microsoft ODBC Driver for SQL Server to communicate with SQL Server. Access the following URL  to download the ODBC Driver for SQL Server for x64: https://go.microsoft.com/fwlink/?LinkId=163712")

  2   C:\xampp\htdocs\LaraUral\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70
      PDO::__construct("sqlsrv:Server=127.0.0.1,1433;Database=xproject2", "sa", "123456789", [])

当前.env配置

DB_CONNECTION=sqlsrv
DB_HOST=127.0.0.1
DB_PORT=1433
DB_DATABASE=xproject2
DB_USERNAME=sa
DB_PASSWORD="123456789"

解决步骤

1. 安装适配Windows7的ODBC驱动

微软ODBC Driver 17及以上版本不再支持Windows7,需安装ODBC Driver 13.1 for SQL Server(支持Windows7的最后一个稳定版本),选择x64版本安装。

2. 启用并配置PHP的sqlsrv扩展

  • 下载适配PHP 8.1 x64、Windows7的sqlsrv和pdo_sqlsrv扩展文件;
  • 将扩展文件放入XAMPP安装目录下的php/ext文件夹;
  • 打开php.ini文件,取消注释或添加以下两行:
    extension=sqlsrv
    extension=pdo_sqlsrv
    
  • 重启XAMPP的Apache服务。

3. 修正.env配置细节

  • 将DB_PASSWORD的引号去掉,改为:
    DB_PASSWORD=123456789
    
    .env文件中字符串类型的配置值无需额外添加引号,否则可能导致密码解析错误。

4. 验证SQL Server连接可用性

  • 确认SQL Server的TCP/IP协议已启用,端口1433处于开放状态;
  • 使用telnet 127.0.0.1 1433测试本地数据库端口连通性;
  • 验证sa账号拥有xproject2数据库的访问权限,密码正确。

5. 清除配置缓存并重新执行迁移

执行以下命令清除Laravel配置缓存:

php artisan config:clear

之后重新运行迁移命令:

php artisan migrate

内容的提问来源于stack exchange,提问作者korvon

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.19 17:25:52