`
baobaoupup
  • 浏览: 468680 次
文章分类
社区版块
存档分类
最新评论

PHP配置SQL Server 2008

 
阅读更多

1、到微软官方去下载新的驱动,下载地址如下:

http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=ccdf728b-1ea0-48a8-a84a-5052214caad9

  官方文档有描述:

  Refer to the documentation that is installed with the driver for a description of the new features in this release. The SQL Server Driver for PHP download is available to all SQL Server users at no additional charge. The SQL Server Driver for PHP is a PHP 5 extension that allows for the reading and writing of SQL Server data from within PHP scripts. The extension provides a procedural interface for accessing data in all editions of SQL Server 2005 and SQL Server 2008.

  根据官方文档的描述,微软提供的Driver是同时提供给SQL Server 2005和SQL Server 2008两个版本使用的。

下载驱动(上边有链接地址)下载过后的驱动包里面的内容如下图:

<!--StartFragment -->

2、需要修改C:/WINDOWS/php.ini中的配置:
  查找;extension_dir 修改为extension_dir="E:/Program Files/php-5.3.1/ext"这里的目录是安装的PHP目录,ext里是PHP的一些扩展文件,运行时需要加载其中的一些,现在连接sqlserver,所以一定要去掉extension_dir 前面的分号;

3、把上图解压开的需要的dll文件拷贝到extension_dir设置的扩展目录里面。

其中‘53’表示php的版本,‘ts’表示启动线程安全,‘nts’表示未启动线程安全,vc6为apache配置,vc9为iis配置

4、修改php.ini实现扩展:

  在php.ini的一大堆;extension=**.dll格式里面添加行,此部分位于以下注释下边一般:

; Windows Extensions

; Note that ODBC support is built in, so no dll is needed for it.

; Note that many DLL files are located in the extensions/ (PHP 4) ext/ (PHP 5)

; extension folders as well as the separate PECL DLL download (PHP 5).

; Be sure to appropriately set the extension_dir directive.

添加拷贝的dll文件,例:

extension=php_sqlsrv_53_ts_v9.dll

  注意=号右边是解开过后的扩展的两个驱动的文件名,必须保证此文件在配置好的扩展目录内,而且需要注意此处最初不需要带“;”。【*:在php.ini文件里面,首部分号的含义代表行注释,如果有分号的时候,服务器在读取配置的时候会略过分号这一行不去读取相关内容,只有没有加分号的行才会被服务器读取。】

  这里解释一下,两个驱动程序的区别在于,php_sqlsrv_ts.dll是线程安全的驱动,如果服务器本身的环境是使用的php5ts.dll,就是用这个驱动;php_sqlsrv_nts.dll不是线程 安全的,这种情况下,服务器运行PHP应该加载的是php5.dll

5、测试配置环境:

  整个过程操作好了过后,写一个test.php测试一下配置的相关环境,测试代码如下:

<?php

phpinfo();

?>

  若出现以下图片证明环境已经配置好了:

最终测试环境图

  

  这里列举一下开发环境,以防出现不同环境有差异的地方:

OS:Windows Server 2008 x64 Enterprise Edition

WebServer:Apache 2.2.11

Database:SQL Server 2008 x64 Enterprise Edition

PHP:5.2.9

  (*:在配置PHP环境的时候,如果是解压缩的版本,在Windows平台上需要拷贝PHP根目录下所有的DLL文件到Windows的目录里面,需要说明的是:Windows 32位系统的目标目录为:$:/Windows/System32,Windows 64位环境的目标目录为:$:/Windows/SysWOW64,这里$符号代表安装操作系统的盘符号。而且本文的Driver好像运行的最低PHP版本应该为5.2.6,官方文档里面说的测试版本是使用的PHP5.2.6,至于低版本是否可以运行,我没有测试。)

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics