简体   繁体   English

无法在Windows中使用Laravel连接到SQL Server

[英]Can not connect to sql server using laravel in windows

I want to use sql server 2017 in laravel 5.7 but I have trouble to connect DB. 我想在laravel 5.7中使用sql server 2017,但我无法连接数据库。

the point is I can cannect with simple dbo string like below 关键是我可以使用下面的简单dbo字符串进行连接

try {
$conn = new PDO ("sqlsrv:Server=DESKTOP-PVSDJ8C;Database=Library", "Nazanin", "12569", [])
} catch(PDOException $e) {
    die("Error connecting to SQL Server: " . $e->getMessage());
}

but when I use laravel to connect 但是当我使用laravel连接时

Illuminate \\ Database \\ QueryException could not find driver (SQL: select * from [book]) Illuminate \\ Database \\ QueryException找不到驱动程序(SQL:从[book]中选择*)

I double check for php extensions and every thing is ok. 我仔细检查了php扩展名,一切正常。

Laravel .env Laravel .env

DB_CONNECTION=sqlsrv
DB_HOST=DESKTOP-PVSDJ8C
DB_PORT=1433
DB_DATABASE=Library
DB_USERNAME=Nazanin
DB_PASSWORD=12569 

Change the default driver in in config->database.php from mysql to 将config-> database.php中的默认驱动程序从mysql更改为

 'default' => 'sqlsrv',

If the bug is not resolved, try the second solution 如果该错误未解决,请尝试第二种解决方案

run

php --version

and then install the sybase version,ensure that it matches up with the version that your VM uses: 然后安装sybase版本,确保它与您的VM使用的版本匹配:

sudo apt-get install freetds-common freetds-bin unixodbc php7.#-sybase

Hope to help you. 希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM