Home > PHP Framework > Laravel > Laravel connection to SQL Server solution

Laravel connection to SQL Server solution

Guanhui
Release: 2020-06-18 18:04:58
forward
5264 people have browsed it

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.

Personal PHP native code solution:

1. Configure the php.ini file, add the dynamic library corresponding to the PHP version, and go to the official download .

extension=php_pdo_sqlsrv_73_nts.dll
extension=php_sqlsrv_73_nts.dll

2. Install the driver because I am using windows server2016, so the driver must see whether Supported.

 [这个是下载地址](https://docs.microsoft.com/zh-cn/sql/connect/odbc/download-odbc-driver-for-sql-server?view=sql-server-ver15 "这个是下载地址")
Copy after login

3. Restart WAMP and use the php -m command to check whether there is php_sqlsrv. The page can also be checked using phpinfo().

注意:windows环境一定要看好你的PHP版本,和path 的默认路径是不是你当前PHP版本对应上,否则你就会采坑。
Copy after login

Connecting to the database

    $db = new \PDO("sqlsrv:Server=ip,1433;Database=sqlname", "username", "pw");
Copy after login

The following is all kinds of fun

  $query = "Select * from table ";
  $res = $db->prepare($query);
  $res->execute();
  $tmp=$res->fetchAll(\PDO::FETCH_ASSOC);
Copy after login

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!

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Composer cannot install laravel
From 1970-01-01 08:00:00
0
0
0
Laravel Space/laravel-backup cannot be installed
From 1970-01-01 08:00:00
0
0
0
Laravel 5.1 Login laravel comes with it No more
From 1970-01-01 08:00:00
0
0
0
Why thinkphp has better performance than laravel?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template