Home>Article>PHP Framework> Laravel connection to SQL Server solution
1.laravel 7.0 connects to mysql by default, and the project needs to connect to sql servel (another system application)
$users = DB::connection('php_sqlsrv') ->select(…); Various errors occur.
extension=php_pdo_sqlsrv_73_nts.dll
extension=php_sqlsrv_73_nts.dll
[这个是下载地址](https://docs.microsoft.com/zh-cn/sql/connect/odbc/download-odbc-driver-for-sql-server?view=sql-server-ver15 "这个是下载地址")
注意:windows环境一定要看好你的PHP版本,和path 的默认路径是不是你当前PHP版本对应上,否则你就会采坑。
$db = new \PDO("sqlsrv:Server=ip,1433;Database=sqlname", "username", "pw");
The following is all kinds of fun
$query = "Select * from table "; $res = $db->prepare($query); $res->execute(); $tmp=$res->fetchAll(\PDO::FETCH_ASSOC);
Recommended tutorial: "Laravel Tutorial"
The above is the detailed content of Laravel connection to SQL Server solution. For more information, please follow other related articles on the PHP Chinese website!