php 配置 wamp 连接 ms sql server 2008
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8754501/
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
configure wamp to connect ms sql server 2008
提问by Shrestha Sunil
I have never connect PHP to MS sql server so getting confusion and trouble for configuring wamp to connect with sql server by following online tutorial. I have install wamp that consist of Apache Version 2.2.21 and PHP Version 5.3.8 and MS Sql server 2008 on same machine. I downloaded the Microsoft Drivers for PHP for SQL Server(SQLSRV20.EXE). and extracted the file to D:\wamp\bin\php\php5.3.8\ext. Then I opened the php.ini file from wamp icon tray and provide the extension path as extension=php_sqlsrv_53_ts_vc9.dll and extension=php_sqlsrv_53_nts_vc9.dll. I have put php file name testsqlserver.php in www root folder of wamp which code is shown below:
我从来没有将 PHP 连接到 MS sql server,所以在按照在线教程配置 wamp 以连接 sql server 时遇到了困惑和麻烦。我在同一台机器上安装了由 Apache 2.2.21 版和 PHP 5.3.8 版和 MS Sql server 2008 组成的 wamp。我下载了 Microsoft Drivers for PHP for SQL Server (SQLSRV20.EXE)。并将文件解压到 D:\wamp\bin\php\php5.3.8\ext。然后我从 wamp 图标托盘打开 php.ini 文件,并提供扩展路径为 extension=php_sqlsrv_53_ts_vc9.dll 和 extension=php_sqlsrv_53_nts_vc9.dll。我已将 php 文件名 testsqlserver.php 放在 wamp 的 www 根文件夹中,其代码如下所示:
<?php
$server = 'mypc/SQLEXPRESS';
$link = mssql_connect($server,'sa','password');
if(!$link)
{
die('something went wrong');
}
?>
When I called testsqlserver.php through browser as localhost:8080\testsqlserver.php. It shows the error: Fatal error: Call to undefined function mssql_connect() in D:\wamp\www\connectsqlserver.php
当我通过浏览器调用 testsqlserver.php 作为 localhost:8080\testsqlserver.php 时。它显示错误: 致命错误:调用 D:\wamp\www\connectsqlserver.php 中未定义的函数 mssql_connect()
am I doing wrong way? or is there anything more to do for this.I have gone through different online search but unable to get the exact solution for this. Would someone help me, it would be great appreciation
我做错了吗?或者还有什么可以做的。我已经通过不同的在线搜索,但无法获得确切的解决方案。有人会帮助我吗,将不胜感激
回答by Dr. Nitin Reddy Katkam
You have to edit your php.ini file located within the WAMP directory. There should be a few lines in there for loading the MS SQL extension but they are commented out; all you need to do is uncomment those lines and restart Apache.
您必须编辑位于 WAMP 目录中的 php.ini 文件。那里应该有几行用于加载 MS SQL 扩展,但它们被注释掉了;您需要做的就是取消对这些行的注释并重新启动 Apache。
I'm using XAMPP and the lines within my php.ini that I have to uncomment are:
我正在使用 XAMPP,我的 php.ini 中必须取消注释的行是:
;extension=php_mssql.dll
;扩展= php_mssql.dll
;extension=php_pdo_mssql.dll
;扩展= php_pdo_mssql.dll
回答by Akash Pandey
Microsoft Drivers for PHP for SQL Server which you have downloaded , support sqlsrv_connect()to establish connection with sql server database
您已下载的Microsoft Drivers for PHP for SQL Server,支持sqlsrv_connect()与sql server数据库建立连接
You should use sqlsrv_connect() function to connect with sql server , mssql_connect is depreciated
you can get full list of function and their description form following link
您应该使用 sqlsrv_connect() 函数与 sql server 连接,mssql_connect 已折旧,
您可以通过以下链接获取完整的函数列表及其描述表
http://msdn.microsoft.com/en-us/library/cc296152%28SQL.90%29.aspx
http://msdn.microsoft.com/en-us/library/cc296152%28SQL.90%29.aspx
回答by Irmantas
I do not currently use wamp, but I think you should enable PHP extensions for this. Click on wamp icon in status bar and enable php_mssql and php_pdo_mssql extensions, then restart apache service.
我目前不使用 wamp,但我认为您应该为此启用 PHP 扩展。单击状态栏中的 wamp 图标并启用 php_mssql 和 php_pdo_mssql 扩展,然后重新启动 apache 服务。