The mysql_connect or ntwlib. dll mentioned earlier is out of date.
Step 1: Install 2 files
1. Driver provided by Microsoft: Microsoft drivers for PHP for SQL Server
This is 3.0 of: http://www.microsoft.com/en-us/download/details.aspx? Id = 20098
2. Pay attention to the following system requirements:
Microsoft SQL Server native client should be installed on the computer running PHP. If SQL server runs PHP on a computer, it is useless.
Step 2: copy the corresponding DLL file to the PHP extension folder.
Copy the files decompressed by Microsoft drivers for PHP for SQL Server to the ext directory of PHP Based on the PHP version information, compilation information, and Application Server Information provided by phpinfo. For example, if PHP is 5.3, use the vc6 compiling and Apache server to copy: php_pdo_sqlsrv_53_ts_vc6.dll and php_sqlsrv_53_ts_vc6.dll. For IIS.
Step 3: add the two extensions to the php. ini file.
One of the two extensions is in the common mode and the other is in the PDO mode. If both are correct, you can find the corresponding information in phpinfo.
The sample code is as follows:
<?php/* Specify the server and connection string attributes. */$serverName = "192.168.120.12";$database = "hrdb";/* Get UID and PWD from application-specific files. */$uid = "username";$pwd = "password"; try { $conn = new PDO("sqlsrv:server=$serverName;Database = $database", $uid, $pwd); $conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); } catch( PDOException $e ) { echo ($e->message); die( "Error connecting to SQL Server" ); } echo "Connected to SQL Server\n"; $query = "select * from TEmployee WHERE FEmployeeID = '000001'"; $stmt = $conn->query( $query ); while ( $row = $stmt->fetch( PDO::FETCH_ASSOC ) ){ var_dump( $row ); } // Free statement and connection resources. $stmt = null; $conn = null; ?>