简体   繁体   English

SQL Server与PHP连接

[英]SQL Server connect with PHP

I have a php script that connects to SQL Server, locally it works fine because I was able to edit the php.ini to include the extension for php_mssql.dll. 我有一个连接到SQL Server的php脚本,在本地它可以正常工作,因为我能够编辑php.ini以包含php_mssql.dll的扩展名。 With the production server, it would be nice if I didn't have to restart the server, so is there a way to add the php_mssql.dll at the start of the script? 对于生产服务器,如果我不必重新启动服务器,那就太好了,因此有没有办法在脚本开始时添加php_mssql.dll? If not, how can I check on the server (linux) to see if the php_mssql.dll file is available if I were to add it into the dynamic extensions section of the php.ini? 如果没有,如果我将其添加到php.ini的动态扩展部分中,如何检查服务器(linux)上的php_mssql.dll文件是否可用?

You can use the dl() function to load the plugin dynamically at runtime: 您可以使用dl()函数在运行时动态加载插件:

<?php

if (!extension_loaded('php_mssql')) {
   dl('php_mssql.dll');
}

Note that this has been disabled in PHP 5.3 when running in SAPI (in-webserver) mode. 请注意,在SAPI(网络服务器中)模式下运行时,已在PHP 5.3中禁​​用此功能。

To test if the mssql extension is loaded, use extension_loaded() : 要测试是否已加载mssql扩展,请使用extension_loaded()

if (extension_loaded("php_mssql")) {}

Note that on Linux, it won't be a .dll, but rather a .so shared object library, and connections to MSSQL will probably require enabling the FreeTDS libraries on the Linux server. 请注意,在Linux上,它将不是.dll,而是.so共享对象库,并且与MSSQL的连接可能需要在Linux服务器上启用FreeTDS库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM