尝试从 PHP 连接到 Azure DB 时出现“调用未定义的函数 sqlsrv_connect()”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7953053/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 03:40:43  来源:igfitidea点击:

"Call to undefined function sqlsrv_connect()" when trying to connect to Azure DB from PHP

phpazureazure-sql-database

提问by Roger

I'm trying to connect from php to Azure DB by

我正在尝试通过以下方式从 php 连接到 Azure DB

$connectionInfo = array("UID" => "xxx@xxx", "pwd" => "xxx", "Database" => "xxx");
$serverName = "tcp:xxx.database.windows.net,1433";
$conn = sqlsrv_connect($serverName, $connectionInfo);

But it gives me

但它给了我

Fatal error: Call to undefined function sqlsrv_connect() in C:\wamp\www...\index.php on line 19

致命错误:在第 19 行调用 C:\wamp\www...\index.php 中未定义的函数 sqlsrv_connect()

回答by astaykov

you have to use the SQL Server native driver for phpat first place, then you can do something like:

您必须首先使用phpSQL Server 本机驱动程序,然后您可以执行以下操作:

$serverName = "tcp:sample.database.windows.net, 1433";

$connectionOptions = array("Database" => "sampleInit", 

                           "UID" => "sampleUsr@sample",

                           "PWD" => "samplePass",

                           "MultipleActiveResultSets" => false);

$conn = sqlsrv_connect($serverName, $connectionOptions);

if($conn === false)

{

     die(print_r(sqlsrv_errors(), true));

}

You can read more on PHP and SQL Azure at following blog post:
http://blogs.msdn.com/b/brian_swan/archive/2010/02/12/getting-started-with-php-and-sql-azure.aspx

您可以在以下博客文章中阅读有关 PHP 和 SQL Azure 的更多信息:http:
//blogs.msdn.com/b/brian_swan/archive/2010/02/12/getting-started-with-php-and-sql-azure。 aspx

回答by Steve Lloyd

I added this dllto the ext/ folder then added extension=php_sqlsrv.dllto the php.ini in the php7/ folder.

将此 dll添加到 ext/ 文件夹,然后添加extension=php_sqlsrv.dll到 php7/ 文件夹中的 php.ini。