My machine is:
XP SP3
Web SQL Server 2008 developer Apache 2.2.2
Python 5.3
Starting from 5.3, PHP will no longer provide MSSQL. dll, so to connect PHP to SQL Server 2008/2012, you must use SQL Server for PHP 2.0/3.0 provided by Microsoft.
Note that php5.4 must be 3.0 and Microsoft SQL Server 2012 native client. PHP official help
Http://php.net/manual/zh/sqlsrv.requirements.php
Microsoft drivers 3.0/2.0 for PHP for SQL Server
Http://www.microsoft.com/en-us/download/details.aspx? Id = 20098
Microsoft SQL Server 2012/2008 native client (if you have installed SQL Server, the corresponding version should be available by default)
Http://msdn.microsoft.com/zh-cn/aa937733
2005 or 2008, version 9, 10 http://go.microsoft.com/fwlink? Linkid = 239647 x86 version for 11 http://go.microsoft.com/fwlink? Linkid = 239648x64
My 5.3 is directly using the Wamp integration environment,
Http://www.wampserver.com/en/
Install the dynamic Connection Library in the ext directory of php5.3
4. Start Wamp and enable the php_sqlsrv _ *. DLL to be used (if you do not see this, refer to the following)
(You can also modify it in PHP. INI)
;;;;;;;;;;;;;;;;;;;;;;; Dynamic extensions ;;;;;;;;;;;;;;;;;;;;;;
Extension = php_pdo_sqlsrv_53_ts_vc9.dll
Extension = php_sqlsrv_53_ts_vc9.dll
Use phpinfo ()
<? PHP
Header ("Content-Type: text/html; charset = UTF-8 ");
$ Servername = "192.168.50.5, 1433"; // local
$ Database = "dadiands ";
$ Uid = "sa ";
$ Pwd = "123456 ";
Try {
$ Conn = new PDO ("sqlsrv: Server = $ servername; database = $ Database", $ uid, $ PWD );
$ Conn-> setattribute (PDO: attr_errmode, PDO: errmode_exception );
} Catch (pdoexception $ e ){
Die ("error connecting to SQL Server". $ E );
}
Echo "connected to SQL Server \ n ";
$ Query = 'select Top 2 * From c_host ';
// $ Query = 'select count (*) from c_host ';
$ Stmt = $ Conn-> query ($ query );
// $ COUNT = $ stmt-> fetchcolumn (0 );
// If (is_array ($ count) {echo 'xx';} else {echo $ count ;}
/// Echo $ count;
/// Var_dump ($ stmt-> fetchall (PDO: fetch_assoc ));
While ($ ROW = $ stmt-> fetch (PDO: fetch_assoc )){
Var_dump ($ row );
}
$ Stmt = NULL;
$ Conn = NULL;
?>