[PHP_PDO_SQLSRV] extension=php_pdo_sqlsrv_53_nts_vc6.dll [PHP_SQLSRV] extension=php_sqlsrv_53_nts_vc6.dll
<?php $serverName = "(127.0.0.1)"; $connectionInfo = array( "UID"=>"root", "PWD"=>"root2010", "Database"=>"master"); $conn = sqlsrv_connect( $serverName, $connectionInfo); if( $conn ) { echo "Connection established.n"; } else { echo "Connection could not be established.n"; die( print_r( sqlsrv_errors(), true)); } ?>
如果使用这个扩展连接Sql server 2005以上版本的sql server(如sql server 2008),你还需要在机器上先安装 SQL Server Native Client :http://download.microsoft.com/download/0/E/6/0E67502A-22B4-4C47-92D3-0D223F117190/sqlncli.msi
这个扩展为php新增了一系列sqlsrv_开头的函数,函数参考如下:
sqlsrv_begin_transaction sqlsrv_cancel sqlsrv_client_info sqlsrv_close sqlsrv_commit sqlsrv_configure sqlsrv_connect sqlsrv_errors sqlsrv_execute sqlsrv_fetch sqlsrv_fetch_array sqlsrv_fetch_object sqlsrv_fetch_metadata sqlsrv_free_stmt sqlsrv_get_config sqlsrv_get_field sqlsrv_has_rows sqlsrv_next_result sqlsrv_num_fields sqlsrv_num_rows sqlsrv_prepare sqlsrv_query sqlsrv_rollback sqlsrv_rows_affected sqlsrv_send_stream_data sqlsrv_server_info
更多详细的说明可以在刚才的自解压的文件中有个 SQLServerDriverForPHP.chm 帮助文件中可以找到打开后点击API Reference节点.
另外看一种odb连接方式,代码如下:
$dbhost = ''; $dbuser = ''; //你的mssql用户名 $dbpass = ''; //你的mssql密码 $dbname = ''; //你的mssql库名 $connect=odbc_connect("Driver={SQL Server};Server=$dbhost;Database=$dbname","$dbuser","$dbpass"); $sql="select * from content"; $exec=odbc_exec($connect,$sql); while($row = (odbc_fetch_array($exec))) { $row['id'] //?取字段值 … }
希望本文所述对大家的php程序设计有所帮助。