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.EXE
from here in C:\Program Files (x86)\PHP\ext
added 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
3 个解决方案
#1
30
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:
如果它确实安装正确,您的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_dir
setting. 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 Mssql extension. You are using microsoft's extension, so use sqlsrv_connect()
, for the API for the microsoft driver, look at SQLSRV_Help.chm
which should be extracted to your ext
directory when you extracted the extension.
你用错了函数。mssql_connect()是Mssql扩展的一部分。您正在使用microsoft的扩展,因此使用sqlsrv_connect(),为microsoft驱动程序的API,查看SQLSRV_Help。当您提取扩展名时,应该将chm提取到您的ext目录中。
#2
1
php.ini probably 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()输出。如果你创建一个包含内容的文件 和访问该页面,HTML输出应该显示几个部分,包括一个带有加载模块的部分。(编辑补充:如上图所示的回答)
#3
0
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。我原来有这条线。
; 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扩展等等。
#1
30
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:
如果它确实安装正确,您的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_dir
setting. 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 Mssql extension. You are using microsoft's extension, so use sqlsrv_connect()
, for the API for the microsoft driver, look at SQLSRV_Help.chm
which should be extracted to your ext
directory when you extracted the extension.
你用错了函数。mssql_connect()是Mssql扩展的一部分。您正在使用microsoft的扩展,因此使用sqlsrv_connect(),为microsoft驱动程序的API,查看SQLSRV_Help。当您提取扩展名时,应该将chm提取到您的ext目录中。
#2
1
php.ini probably 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()输出。如果你创建一个包含内容的文件 和访问该页面,HTML输出应该显示几个部分,包括一个带有加载模块的部分。(编辑补充:如上图所示的回答)
#3
0
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。我原来有这条线。
; 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扩展等等。