PHP 致命错误:调用未定义的函数 mssql_connect()

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9986804/
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 08:01:51  来源:igfitidea点击:

PHP Fatal error: Call to undefined function mssql_connect()

phpsql-serveriisiis-7

提问by Greg

I've never used php before and am trying to connect to a SQL Server 2008 instance on a Windows machine running IIS7 and PHP5.3.

我以前从未使用过 php,我正在尝试连接到运行 IIS7 和 PHP5.3 的 Windows 机器上的 SQL Server 2008 实例。

I have downloaded and installed SQLSRV30.EXEfrom herein C:\Program Files (x86)\PHP\extadded this to C:\Program Files (x86)\PHP\php.ini:

我已经下载并安装SQLSRV30.EXE这里C:\Program Files (x86)\PHP\ext添加到了C:\Program Files (x86)\PHP\php.ini

extension=php_sqlsrv_53_nts.dll

Then restarted the entire server. I still get fatal errors in my log file saying:

然后重新启动整个服务器。我的日志文件中仍然出现致命错误,内容如下:

PHP Fatal error:  Call to undefined function mssql_connect()

What do I need to do to connect to Microsoft SQL Server 2008 from PHP 5.3 running on IIS7/Windows Server 2008? I'm sure it's something really dumb that I'm missing...

我需要做什么才能从运行在 IIS7/Windows Server 2008 上的 PHP 5.3 连接到 Microsoft SQL Server 2008?我确定我错过了一些非常愚蠢的东西......

FULL PHPINFO -->http://demo.mandibleweb.com/zapified/hello.php

完整的 PHPINFO --> http://demo.mandibleweb.com/zapified/hello.php

phpinfo():

phpinfo():

PHP Version 5.3.10





System 

Windows NT MWD001 6.1 build 7601 (Windows Server 2008 R2 Standard Edition Service Pack 1) i586 



Build Date 

Feb 2 2012 20:10:58 



Compiler 

MSVC9 (Visual C++ 2008) 



Architecture 

x86 



Configure Command 

cscript /nologo configure.js "--enable-snapshot-build" "--enable-debug-pack" "--disable-zts" "--disable-isapi" "--disable-nsapi" "--without-mssql" "--without-pdo-mssql" "--without-pi3web" "--with-pdo-oci=C:\php-sdk\oracle\instantclient10\sdk,shared" "--with-oci8=C:\php-sdk\oracle\instantclient10\sdk,shared" "--with-oci8-11g=C:\php-sdk\oracle\instantclient11\sdk,shared" "--with-enchant=shared" "--enable-object-out-dir=../obj/" "--enable-com-dotnet" "--with-mcrypt=static" "--disable-static-analyze" 



Server API 

CGI/FastCGI 



Virtual Directory Support 

disabled 



Configuration File (php.ini) Path 

C:\Windows 



Loaded Configuration File 

C:\Program Files (x86)\PHP\php.ini 

回答by F21

I have just tried to install that extension on my dev server.

我刚刚尝试在我的开发服务器上安装该扩展。

First, make sure that the extension is correctly enabled. Your phpinfo()output doesn't seem complete.

首先,确保正确启用了扩展。您的phpinfo()输出似乎不完整。

If it is indeed installed properly, your phpinfo()should have a section that looks like this: enter image description here

如果确实安装正确,您phpinfo()应该有一个如下所示的部分: 在此处输入图片说明

If you do not get that section in your phpinfo(). Make sure that you are using the right version. There are both non-thread-safe and thread-safe versions of the extension.

如果您的phpinfo(). 确保您使用的是正确的版本。该扩展有非线程安全和线程安全版本。

Finally, check your extension_dirsetting. By default it's this: extension_dir = "ext", for most of the time it works fine, but if it doesn't try: extension_dir = "C:\PHP\ext".

最后,检查您的extension_dir设置。默认情况下它是这样的:extension_dir = "ext",在大多数情况下它工作正常,但如果它不尝试:extension_dir = "C:\PHP\ext"

===========================================================================

================================================== ==========================

EDIT given new info:

编辑给出新信息:

You are using the wrong function. mssql_connect()is part of the Mssqlextension. You are using microsoft's extension, so use sqlsrv_connect(), for the API for the microsoft driver, look at SQLSRV_Help.chmwhich should be extracted to your extdirectory when you extracted the extension.

您使用了错误的功能。mssql_connect()Mssql扩展的一部分。您使用的是微软的扩展,所以使用sqlsrv_connect(), 对于微软驱动程序的 API,看看在您解压扩展时SQLSRV_Help.chm应该将哪个解压到您的ext目录中。

回答by Chris K

php.iniprobably needs to read: extension=ext\php_sqlsrv_53_nts.dll

php.ini可能需要阅读: extension=ext\php_sqlsrv_53_nts.dll

Or move the file to same directory as the php executable. This is what I did to my php5 install this week to get odbc_pdo working. :P

或者将文件移动到与 php 可执行文件相同的目录。这就是我本周对 php5 安装所做的工作,以使 odbc_pdo 正常工作。:P

Additionally, that doesn't look like proper phpinfo() output. If you make a file with contents
<? phpinfo(); ?>and visit that page, the HTML output should show several sections, including one with loaded modules. (Edited to add: like shown in the screenshot of the above accepted answer)

此外,这看起来不像是正确的 phpinfo() 输出。如果您创建一个包含内容的文件
<? phpinfo(); ?>并访问该页面,则 HTML 输出应显示多个部分,其中一个部分包含已加载的模块。(编辑添加:如上面接受的答案的屏幕截图所示)

回答by M Shiraz Baig

I am using IIS and mysql (directly downloaded, without wamp or xampp) My php was installed in c:\php I was getting the error of "call to undefined function mysql_connect()" For me the change of extension_dir worked. This is what I did. In the php.ini, Originally, I had this line

我正在使用 IIS 和 mysql(直接下载,没有 wamp 或 xampp)我的 php 安装在 c:\php 我收到“调用未定义函数 mysql_connect()”的错误对我来说,extension_dir 的更改起作用了。这就是我所做的。在 php.ini 中,原来我有这一行

; On windows: extension_dir = "ext"

; 在 Windows 上:extension_dir = "ext"

I changed it to:

我把它改成:

; On windows: extension_dir = "C:\php\ext"

; 在 Windows 上:extension_dir = "C:\php\ext"

And it worked. Of course, I did the other things also like uncommenting the dll extensions etc, as explained in others remarks.

它奏效了。当然,我还做了其他事情,例如取消对 dll 扩展名的注释等,如其他评论中所述。