1. Download Microsoft PHP Connection driver: SQLSRV30.EXE (5.4 corresponding, native Client to be used)/sqlsrv20. EXE (5.3 Corresponding, native Client to use 2008)
2. Unzip the SQLSERV30.EXE, copy the corresponding extension to PHP ext directory
3. Configure PHP.ini
Extension=php_sqlsrv_54_ts.dll (54 for 5.4, TS for thread safety, NTS for non-thread safe)
Mssql.secure_connection = Off to on many tutorials did not write this
4. Restart Iis/apache
5. Configuring TCP/IP connections on SQL Server servers
6. Download and install SQL Server Native Client in PHP
7. Test code
<?PHPHeader("Content-type:text/html;charset=utf-8");classmssql{Private $host; Private $username; Private $password; Private $database; Private $handle; Private function__construct (Array $config){ $this-Host =$config[' Host ']; $this-Username =$config[' username ']; $this-Password =$config[' Password ']; $thisDatabase =$config[' Database ']; $this-init (); } Private functioninit () {$dsn= ' Sqlsrv:server = '.$thisHost. '; Database = '.$this-database; $this-Handle =NewPDO ($dsn,$thisUsername,$this-password); } Public Static functionGetInstance (Array $config=NULL) { if(NULL==$config) { return NULL; } Static $db=NULL; if(NULL==$db) { $c=__class__; $db=New $c($config); }; return $db-handle; }}$config=Array( ' Host ' = ' 192.168.0.152,1433 ', ' database ' = ' timetracker ', ' username ' = ' sa ', ' password ' and ' 123 ');$mssql= Mssql::getinstance ($config);$result=$mssql->query (' SELECT * from T_sys_userinfo ');foreach($result as $row){ Echo $row[2];}?>
PHP5.4 Connecting to SQL Server