php sqlserver扩展,加载 Microsoft Drivers for PHP - SQL Server | Microsoft Docs

加载 Microsoft Drivers for PHP for SQL ServerLoading the Microsoft Drivers for PHP for SQL Server

02/11/2019

本文内容

本页提供有关将 Microsoft Drivers for PHP for SQL ServerMicrosoft Drivers for PHP for SQL Server 加载到 PHP 进程空间中的说明。This page provides instructions for loading the Microsoft Drivers for PHP for SQL ServerMicrosoft Drivers for PHP for SQL Server into the PHP process space.

You can download the prebuilt drivers for your platform from the Microsoft Drivers for PHP for SQL Server GitHub project page. 每个安装包都包含线程和非线程变体中的 SQLSRV 和 PDO_SQLSRV 驱动程序文件。Each installation package contains SQLSRV and PDO_SQLSRV driver files in threaded and non-threaded variants. 在 Windows 上,它们也可用于 32 位和 64 位变体。On Windows, they are also available in 32-bit and 64-bit variants. See System Requirements for the Microsoft Drivers for PHP for SQL Server for a list of the driver files that are contained in each package. 驱动程序文件必须与 PHP 环境的 PHP 版本、体系结构和线程性匹配。The driver file must match the PHP version, architecture, and threadedness of your PHP environment.

在 Linux 和 macOS 上,可以也使用 PECL 安装驱动程序,如安装教程中所示。On Linux and macOS, the drivers can alternatively be installed using PECL, as found in the installation tutorial.

还可以在构建 PHP 时或使用 phpize 从源生成驱动程序。You can also build the drivers from source either when building PHP or by using phpize. 如果选择从源生成驱动程序,则可以通过在生成 PHP 时将 --enable-sqlsrv=static --with-pdo_sqlsrv=static(在 Linux 和 macOS 上)或 --enable-sqlsrv=static --with-pdo-sqlsrv=static(在 Windows 上)添加到 ./configure 命令来将驱动程序静态生成到 PHP 中,而不是将它们生成为共享扩展。If you choose to build the drivers from source, you have the option of building them statically into PHP instead of building them as shared extensions by adding --enable-sqlsrv=static --with-pdo_sqlsrv=static (on Linux and macOS) or --enable-sqlsrv=static --with-pdo-sqlsrv=static (on Windows) to the ./configure command when building PHP. 有关 PHP 生成系统和 phpize 的详细信息,请参阅 PHP 文档。For more information on the PHP build system and phpize, see the PHP documentation.

将驱动程序文件移动到扩展目录中Moving the Driver File into Your Extension Directory

驱动程序文件必须位于 PHP 运行时可以找到它的目录中。The driver file must be located in a directory where the PHP runtime can find it. 最简单的方法是将驱动程序文件放入默认的 PHP 扩展目录中。要查找默认目录,只需在 Windows 上运行 php -i | sls extension_dir 或在 Linux/macOS 上运行 php -i | grep extension_dir。It is easiest to put the driver file in your default PHP extension directory - to find the default directory, run php -i | sls extension_dir on Windows or php -i | grep extension_dir on Linux/macOS. 如果使用的不是默认扩展目录,请使用 extension_dir 选项在 PHP 配置文件 (php.ini) 中指定一个目录。If you are not using the default extension directory, specify a directory in the PHP configuration file (php.ini), using the extension_dir option. 例如,在 Windows 上,如果已将驱动程序文件置于 c:\php\ext 目录中,则将以下行添加到 php.ini 中:For example, on Windows, if you have put the driver file in your c:\php\ext directory, add the following line to php.ini:

extension_dir = "c:\PHP\ext"

在 PHP 启动时加载驱动程序Loading the Driver at PHP Startup

若要在 PHP 启动时加载 SQLSRV 驱动程序,首先要将驱动程序文件移动到扩展目录中。To load the SQLSRV driver when PHP is started, first move a driver file into your extension directory. 然后,按如下步骤操作:Then, follow these steps:

要启用 SQLSRV 驱动程序,请通过向扩展部分添加以下行并适当地更改文件名来修改 php.ini :To enable the SQLSRV driver, modify php.ini by adding the following line to the extension section, changing the filename as appropriate:

在 Windows 上:On Windows:

extension=php_sqlsrv_72_ts.dll

在 Linux 上,如果已经下载用于分发的预生成二进制文件:On Linux, if you have downloaded the prebuilt binaries for your distribution:

extension=php_sqlsrv_72_nts.so

如果已从源代码或使用 PECL 编译了 SQLSRV 二进制文件,则会将其命名为 sqlsrv.so:If you have compiled the SQLSRV binary from source or with PECL, it will instead be named sqlsrv.so:

extension=sqlsrv.so

要启用 PDO_SQLSRV 驱动程序,PHP 数据对象 (PDO) 必须可用作内置扩展,或用作动态加载的扩展。To enable the PDO_SQLSRV driver, the PHP Data Objects (PDO) extension must be available, either as a built-in extension, or as a dynamically loaded extension.

在 Windows 上,预生成的 PHP 二进制文件带有内置的 PDO,因此无需修改 php.ini 即可加载它。On Windows, the prebuilt PHP binaries come with PDO built-in, so there is no need to modify php.ini to load it. 但是,如果已从源编译 PHP 并指定了要生成的单独 PDO 扩展,它将被命名为 php_pdo.dll,并且必须将其复制到扩展目录中并将以下行添加到 php.ini 中:If, however, you have compiled PHP from source and specified a separate PDO extension to be built, it will be named php_pdo.dll, and you must copy it to your extension directory and add the following line to php.ini:

extension=php_pdo.dll

在 Linux 上,如果使用系统的包管理器安装了 PHP,则 PDO 可能会作为名为 pdo.so 的动态加载扩展进行安装。On Linux, if you have installed PHP using your system's package manager, PDO is probably installed as a dynamically loaded extension named pdo.so. 必须先加载 PDO 扩展,然后才能加载 PDO_SQLSRV 扩展,否则,加载会失败。The PDO extension must be loaded before the PDO_SQLSRV extension, or loading will fail. 扩展通常使用单个 .ini 文件加载,这些文件在 php.ini 之后读取。Extensions are usually loaded using individual .ini files, and these files are read after php.ini. 因此,如果通过其自己的 .ini 文件加载 pdo.so,则需要一个可在 PDO 之后加载 PDO_SQLSRV 驱动程序的单独文件。Therefore, if pdo.so is loaded through its own .ini file, a separate file loading the PDO_SQLSRV driver after PDO is required.

要查找扩展特定的 .ini 文件位于哪个目录,请运行 php --ini 并记下 Scan for additional .ini files in: 下列出的目录。To find out which directory the extension-specific .ini files are located, run php --ini and note the directory listed under Scan for additional .ini files in:. 查找加载 pdo.so 的文件。Find the file that loads pdo.so. 此文件的前缀可能是数字(如 10-pdo.ini)。It is likely prefixed by a number, such as 10-pdo.ini. 数字前缀表示加载 .ini 文件的顺序,而没有数字前缀的文件则按字母顺序加载。The numerical prefix indicates the loading order of the .ini files, while files that do not have a numerical prefix are loaded alphabetically. 创建一个文件以加载名为 30-pdo_sqlsrv.ini(任何大于 pdo.ini 前缀的数字都适用)或 pdo_sqlsrv.ini(如果 pdo.ini 没有数字前缀)的 PDO_SQLSRV 驱动程序文件,然后将以下行添加到驱动程序,并相应地更改文件名:Create a file to load the PDO_SQLSRV driver file called either 30-pdo_sqlsrv.ini (any number larger than the one that prefixes pdo.ini works) or pdo_sqlsrv.ini (if pdo.ini is not prefixed by a number), and add the following line to it, changing the filename as appropriate:

extension=php_pdo_sqlsrv_72_nts.so

与 SQLSRV 一样,如果已从源或使用 PECL 编译了 PDO_SQLSRV 二进制文件,则会将其命名为 pdo_sqlsrv.so:As with SQLSRV, if you have compiled the PDO_SQLSRV binary from source or with PECL, it will instead be named pdo_sqlsrv.so:

extension=pdo_sqlsrv.so

将此文件复制到包含其他 .ini 文件的目录中。Copy this file to the directory that contains the other .ini files.

如果使用内置的 PDO 支持从源编译 PHP,则不需要单独的 .ini 文件,可以将上面相应的行添加到 php.ini 中。If you have compiled PHP from source with built-in PDO support, you do not require a separate .ini file, and you can add the appropriate line above to php.ini.

重新启动 Web 服务器。Restart the Web server.

备注

若要确定驱动程序是否已成功加载,请运行可调用 phpinfo() 的脚本。To determine whether the driver has been successfully loaded, run a script that calls phpinfo().

有关 php.ini 指令的详细信息,请参阅核心 php.ini 指令说明 。For more information about php.ini directives, see Description of core php.ini directives.

另请参阅See Also

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值