致命错误:未捕获错误:调用未定义函数sqlsrv_connect() [英] Fatal error: Uncaught Error: Call to undefined function sqlsrv_connect()

查看:257
本文介绍了致命错误:未捕获错误:调用未定义函数sqlsrv_connect()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试连接到我们可以通过"Microsoft SQL Server Management Studio"访问的SQL Server:

I am trying to connect to a SQL Server that we can access through "Microsoft SQL Server Management Studio":

我已经尝试了很多我在SO上看到过的东西,但是没有任何效果.在test.php页面上运行以下代码时,出现错误Fatal error: Uncaught Error: Call to undefined function sqlsrv_connect() in C:\Apache24\htdocs\test.php:52 Stack trace: #0 {main} thrown in C:\Apache24\htdocs\test.php on line 52:

I've tried a bunch of different things I've seen on SO but nothing has worked. I get the error Fatal error: Uncaught Error: Call to undefined function sqlsrv_connect() in C:\Apache24\htdocs\test.php:52 Stack trace: #0 {main} thrown in C:\Apache24\htdocs\test.php on line 52 when running the following code on the test.php page:

$serverName = "SERVER.DOMAIN.COM, 1433"; //serverName\instanceName, portNumber (default is 1433)
$connectionInfo = array( "Database"=>"DB_NAME", "UID"=>"USER", "PWD"=>"PASS");
$ma_conn = sqlsrv_connect( $serverName, $connectionInfo);

if( $ma_conn ) {
     echo "Connection established.<br />";
}else{
     echo "Connection could not be established.<br />";
     die( print_r( sqlsrv_errors(), true));
}

我的php.ini文件经过了许多不同的扩展名启用,但是没有一个起作用.我已经尝试了以下所有方法:

My php.ini file has gone through many different extensions being enabled, but none have worked. I've tried all of the following:

extension = php_sqlsrv_56_ts.dll
extension=php_sqlsrv_55_ts.dll
extension=php_sqlsrv_55_nts.dll
extension=php_sqlsrv_55_ts.dll
extension=php_pdo_sqlsrv_55_ts.dll
extension=php_pdo_mssql.dll
extension=php_pdo_mysql.dll

目前,我有:

extension_dir = "c:\apache24\php7\ext\"
extension=php_pdo.dll
extension=php_pgsql.dll
[PHP_SQLSRV]
extension=php_sqlsrv_54_ts.dll
[PHP_PDO_SQLSRV]
extension=php_pdo_sqlsrv_54_ts.dll

在带有CMD的Apache和PHP的机器上,我得到以下信息:

On the machine with Apache and PHP in CMD I get the following:

Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.

C:\Windows\system32>php -c c:\apache24\php7\php.ini -v -display_startup_errors=1

PHP Warning:  PHP Startup: Unable to load dynamic library 'c:\apache24\php7\ext\ php_pdo.dll' - %1 is not a valid Win32 application.
 in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'c:\apache24\php7\ext\ php_sqlsrv_54_ts.dll' - %1 is not a valid Win32 application.
 in Unknown on line 0 PHP
Warning:  PHP Startup: Unable to load dynamic library 'c:\apache24\php7\ext\ php_pdo_sqlsrv_54_ts.dll' - %1 is not a valid Win32 application.
 in Unknown on line 0
PHP 7.0.10 (cli) (built: Aug 18 2016 09:48:53) ( ZTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies

C:\Windows\system32>

我还下载了SQLSRV32.EXE并将其运行在C:\Apache24\php7\ext文件夹中.

I've also downloaded and ran SQLSRV32.EXE inside of the C:\Apache24\php7\ext folder.

我有:

  • Windows Server 2012 RS win64
  • Apache 2.4.23 win64
  • PHP 7.0.10 win64
  • Microsoft SQL Server 2012本机客户端win64
  • Microsoft Visual C ++ 2012 x64及更高版本x86可再发行内容(两个不同)
  • Microsoft Visual C ++ 2015可再发行组件(x64和x86)-14.0.23026
  • 用于SQL Server的Microsoft ODBC驱动程序11

推荐答案

符合php.ini(php_sqlsrv_XX_ts.dll)中的尝试列表,您已激活PHP v5.5和v5.6的扩展.但是,由于您正在运行PHP 7.0,因此需要下载并激活相应的用于SQLSRV扩展的php.net页面上进行了声明

Conform to the list of your tries in php.ini (php_sqlsrv_XX_ts.dll), you have activated extensions for PHP v5.5 and v5.6. But, since you are running PHP 7.0, you need to download and activate the corresponding Microsoft Drivers for PHP for SQL Server. It seems that you need to download the driver version 4.0. This is stated on the php.net page for SQLSRV extension.

SQLSRV扩展受Microsoft支持,并且可用于 在此处下载: http://msdn.microsoft.com/en-us/sqlserver /ff657782.aspx .

The SQLSRV extension is supported by Microsoft and available for download here: http://msdn.microsoft.com/en-us/sqlserver/ff657782.aspx.

在这里您可以找到

Here you can find the instructions for Loading the PHP SQL Driver. You'll probably receive a file like php_sqlsrv_7_XX.dll with XX: "ts" or "nts" (thread safe or non-thread safe). I think you need the thread safe version.

否则,请使用 MS SQL Server(PDO) PDO驱动程序(请阅读链接中的安装"部分!),并使用 PDO_SQLSRV DSN (连接字符串)和 PDO 常规功能,例如所有驾驶员共有的.然后,驱动程序将以extension=php_pdo_sqlsrv_7_ts.dll的形式添加到php.ini中(检查同一页面上的说明:

Otherwise, use MS SQL Server (PDO) PDO driver (read the "Installation" part in the link!) with the PDO_SQLSRV DSN (connection string) and the PDO general functionality, e.g. common to all drivers. The driver will be added to the php.ini as extension=php_pdo_sqlsrv_7_ts.dll then (check the same page for instructions: Loading the PHP SQL Driver). If you ask me, I would really choose this option.

Nota Bene:不要忘记在每次配置更改后重新启动Web服务器和/或数据库服务!

Nota Bene: Don't forget to restart the web server and/or the db service after each change in configs!

祝你好运.

这篇关于致命错误:未捕获错误:调用未定义函数sqlsrv_connect()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆