[英]How to connect to MSSQL DB with wamp64
I'm using wamp64 as localhost for programming my php code.我使用 wamp64 作为本地主机来编写我的 php 代码。
But now I got asked to connect to a MSSQL DB.但是现在我被要求连接到 MSSQL 数据库。
I searched for answers on how to do it and found sqlsrv_connect()
function.我搜索了有关如何操作的答案并找到了sqlsrv_connect()
函数。
When I call this function I get this error:当我调用此函数时,出现此错误:
Uncaught Error: Call to undefined function sqlsrv_connect() in C:\\wamp64\\未捕获的错误:调用 C:\\wamp64\\ 中未定义的函数 sqlsrv_connect()
I'm not familiar with this, so could someone help me with instructions on how to fix this?我对此不熟悉,所以有人可以帮助我提供有关如何解决此问题的说明吗?
I also read that I need to install!?我也读到我需要安装!? (I don't understand how to do this) (我不明白如何做到这一点)
My PHP version is 7.2.4我的 PHP 版本是 7.2.4
This is my code:这是我的代码:
$serverName = "server, 1433"; //serverName\instanceName, portNumber
$connectionInfo = array( "Database"=>"DB", "UID"=>"USERNAME", "PWD"=>"PASSWORD");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn ) {
echo "Connection established.<br />";
}else{
echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));
}
I also downloaded some EXE files :我还下载了一些EXE 文件:
SQLSRV30.EXE, SQLSRV31.EXE, SQLSRV32.EXE, SQLSRV40.EXE SQLSRV30.EXE、SQLSRV31.EXE、SQLSRV32.EXE、SQLSRV40.EXE
What do they mean?他们的意思是什么? Which one should I have?我应该拥有哪一个?
Please someone help me with this.请有人帮我解决这个问题。
Edit: After trying the answer, I got this error:编辑:尝试答案后,我收到此错误:
PHP Startup: Unable to load dynamic library 'sqlsrv_72_nts' PHP 启动:无法加载动态库 'sqlsrv_72_nts'
I solved it ~ PHP Version 7.2.4我解决了~ PHP 7.2.4版
pdo_sqlsrv : 5.3.0+11108 pdo_sqlsrv:5.3.0+11108
1.download the proper version sqlsrv and sqlsrv pdo 1.下载正确版本的sqlsrv和sqlsrv pdo
2.put it into XAMPP\\PHP\\ext folder 2.放入XAMPP\\PHP\\ext文件夹
3.after that write the line into php.ini > module setting 3.之后将这一行写入 php.ini > module setting
extension=php_pdo_sqlsrv_72_ts.dll扩展名=php_pdo_sqlsrv_72_ts.dll
extension=php_sqlsrv_72_ts.dll扩展名=php_sqlsrv_72_ts.dll
4.let's make a test for MSSQL still there is an error msg for recommending you to download ODBC Driver for SQL 4.让我们测试一下MSSQL仍然有一个错误消息建议您下载ODBC Driver for SQL
(mine is Command Line Utilities 11 for SQL Server® X86) (我的是 SQL Server® X86 的命令行实用程序 11)
6.fire the test.php again everything works! 6.fire test.php 再次一切正常!
I followed @SayedMohdAli's steps and Got this error:我按照@SayedMohdAli 的步骤进行操作并出现此错误:
PHP Startup: Unable to load dynamic library 'sqlsrv_72_nts' PHP 启动:无法加载动态库 'sqlsrv_72_nts'
I changed the name from 'sqlsrv_72_nts'
to 'sqlsrv_72_ts'
and It worked.我将名称从'sqlsrv_72_nts'
更改为'sqlsrv_72_ts'
并且它起作用了。
@SayedMohdAli thanks for helping me with this getting started. @SayedMohdAli 感谢您帮助我开始这个过程。 Solved it with your help.在您的帮助下解决了它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.