|
本文主要介绍搭建PHP5和SQL Server 2005开发环境例子:SQL Server 2005 php驱动是php5的一个扩展,它提供访问SQL Server 2005和SQL Server 2000.该扩展数据访问接口可以应用在所有版本(包括体验版)的SQL Server 2005和SQL Server 2000.该SQL Server 2005 php驱动支持Windows验证,参数绑定(译预处理),大对象流,原数据访问和错误处理.
在你使用IIS:Internet Information Services和FastCGI组件,该驱动拥有良好的性能和稳定的Windows平台. 关于FastCGI组件可访问:FastCGI for IIS. 配置:
1.将php_sqlsrv.dll 或 php_sqlsrv_ts.dll 放到PHP的扩展目录中(PHP\EXT). 2.编辑php.ini文件,添加以下扩展: extension=php_sqlsrv.dll 或 extension=php_sqlsrv_ts.dll 3.重启服务器.
示例: <?php
$dbbase='testlab';
$uid='sa';
$pwd='infobus';
$connectionInfo=array("Database"=>$dbbase,"UID"=>$uid,"PWD"=>$pwd);
$serverName="JUJUMAOEXPRESS";
if(!($conn=sqlsrv_connect($serverName,$connectionInfo))){
echo "Connection could not be established. ";
die(print_r(sqlsrv_errors(),true));
}
$tSQL="SELECT login_mail FROM account";
if(!($stmt=sqlsrv_query($conn,$tSQL))){
echo "Error in statement. ";
die(print_r(sqlsrv_errors(),true));
}
if(!(sqlsrv_fetch($stmt))){
echo "Error in retrieving row. ";
die(print_r(sqlsrv_errors(),true));
}
$loginmail=sqlsrv_get_field($stmt,1);
echo $loginmail;

sqlsrv_close($conn);
?>
我已经在XP SP2+Apache 2.2+PHP 5.2.6+SQL Server 2005中测试通过!
如果你在启动应用服务器时提示: The application has failed to start because php5.dll was not found 或 缺少php5.dll 请访问:http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3175669&SiteID=1 或去PHP下载mirror包: http://us3.php.net/get/php-5.2.5-nts-Win32.zip/from/a/mirror 解开包后把php5.dll放入你的PHP根目录即可
|