A few days ago, a project database used MSSQL. Then I need to call the data in it for analysis. Because I am good at PHP, I want to use PHP directly to connect to MSSQL.
Generally, the database used by PHP is MySQL, so you need to install the extension first to make PHP support MSSQL, and Microsoft has the corresponding extension download.
The general steps are as follows:
1. Download the PHP extension for connecting to MSSQL: https://docs.microsoft.com/en-us/sql/connect/php/system-requirements-for-the-php-sql-driver?view=sql -server-2017
Extension download address: https://docs.microsoft.com/zh-cn/sql/connect/php/download-drivers-php-sql-server?view=sql -server-2017

? You can see the extended version for each version. I downloaded the latest 5.6, because the PHP version uses 7.3.2
After downloading, copy the corresponding dll crisis to the ext directory of the php installation directory, and add extensions in php. ini:
extension=php_ pdo_ sqlsrv_ 73_ nts_ x64 extension=php_ sqlsrv_ 73_ nts_ x64
2. After installing the extension, you also need to install the corresponding ODBC driver on the computer: https://docs.microsoft.com/zh-cn/sql/connect/odbc/download-odbc-driver-for-sql-server?view=sql -server-2017

Download and install the driver according to the corresponding extension version.
3. Connect MSSQL
If Larave is used, select DB in. env_ Set Connection to sqlsrv.
If you use PHP connection directly:
$connectionInfo = array( "Database" => 'table', "UID" => 'sa', "PWD" => '123456' ); $conn = sqlsrv_ connect('127.0.0.1', $connectionInfo); if ($conn) { $sql = "select * from users; $data = sqlsrv_ query($conn, $sql); }