致命错误:调用未定义的函数 sqlsrv_connect() [英] Fatal error: Call to undefined function sqlsrv_connect()
问题描述
我遇到了很多关于同一主题问题的帖子,但是我仍然无法解决它,所以我问.我正在尝试在我的 php 脚本中连接到 sql.我的连接字符串是:
I have come across quite a few post regarding the same subject question, however I am still unable to resolve it and so I ask. I am trying to connect to sql in my php script. My connection string is:
/* Specify the server and connection string attributes. */
$serverName = "xxx-PCSQLExpress";
$connectionOptions = array("Database"=>"Salesforce");
$conn = sqlsrv_connect($serverName, $connectionOptions);
if($conn === false)
{
die(print_r(sqlsrv_errors(), true));
}
我已安装并在位于 wamp 文件夹下的 php.ini
文件中包含以下内容:C:wampinphpphp5.4.16
:
I have installed and included the following in my php.ini
file located under the wamp folder: C:wampinphpphp5.4.16
:
extension=c:/wamp/bin/php/php5.4.16/ext/php_sqlsrv_53_ts.dll
我的 wampserver
运行良好,wampapache
和 wampsqld
服务也运行良好.我能够成功执行 php.exe.但是,我无法连接到我的数据库所在的 SQL Server 2008 R2
.请帮忙!
My wampserver
is running fine and so are the wampapache
and wampsqld
services. I am able to execute php.exe successfully. However I am unable to make the connection to SQL Server 2008 R2
where my database is located. Please help!
编辑 1:当我尝试连接到 SQL Server 2008 R2
时,wamp 服务器正在运行 wampmysql 服务.这可能是原因吗?我应该使用 MySQL
而不是 SQL
吗?有什么指点吗?
EDIT 1: The wamp server is running the wampmysql service while I am trying to connect to SQL Server 2008 R2
. Could this be the reason? Should I be using MySQL
instead of SQL
? Any pointers?
编辑 2:我在运行 phpinfo()
时根本看不到 sqlsrv
部分,尽管我添加了 extension=php_sqlsrv_54_ts.dll
在位于 wamp 服务器的 bin 文件夹中的 php.ini
文件中.
EDIT 2: I do not see sqlsrv
section at all when I run phpinfo()
though I have added extension=php_sqlsrv_54_ts.dll
in the php.ini
file located in the bin folder of the wamp server.
推荐答案
这 帮助我找到了答案.有两个 php.ini
文件,就我而言,用于 wamp.一个在 php 文件夹下,另一个在 C:wampinapacheApachex.x.xin
文件夹中.当通过sqlsrv_connect
函数连接SQL时,我们指的是apache
文件夹中的php.ini
文件.将以下内容(根据您的版本)添加到此文件中:
This helped me get to my answer. There are two php.ini
files located, in my case, for wamp. One is under the php folder and the other one is in the C:wampinapacheApachex.x.xin
folder. When connecting to SQL through sqlsrv_connect
function, we are referring to the php.ini
file in the apache
folder. Add the following (as per your version) to this file:
extension=c:/wamp/bin/php/php5.4.16/ext/php_sqlsrv_53_ts.dll
这篇关于致命错误:调用未定义的函数 sqlsrv_connect()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!