简体   繁体   English

如何使用 wamp64 连接到 MSSQL DB

[英]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

  1. Go to https://docs.microsoft.com/zh-tw/sql/connect/odbc/download-odbc-driver-for-sql-server?view=sql-server-2017 then download the proper file转到https://docs.microsoft.com/zh-tw/sql/connect/odbc/download-odbc-driver-for-sql-server?view=sql-server-2017然后下载正确的文件

(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.

相关问题 解析错误:语法错误,第 9 行 C:\\wamp64\\www\\bluepeatshop\\db_connect.php 中出现意外的 &#39;:&#39; - Parse error: syntax error, unexpected ':' in C:\wamp64\www\bluepeatshop\db_connect.php on line 9 如何在 wamp64 上安装 php_imagick - How to install php_imagick on wamp64 警告:mysqli_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: YES) in C:\wamp64\www\web\db.php 在第 3 行 - Warning: mysqli_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: YES) in C:\wamp64\www\web\db.php on line 3 错误:c:/ wamp64或PATH中的PHP - error: c:/wamp64 or PHP in PATH 使用WAMP64的OCI8配置 - OCI8 configuration with WAMP64 无法完全删除/卸载wamp64文件 - Can't completely remove/uninstall wamp64 files WAMP64 SSL用于file_get_contents - WAMP64 ssl for file_get_contents 如何更正未定义的索引:第12行的C:\\ wamp64 \\ www \\ Form \\ addtodatabase.php中的名字错误 - how to rectify Undefined index: firstname in C:\wamp64\www\Form\addtodatabase.php on line 12 error PHP MsSQL WAMP-无法连接到MSSQL - PHP MsSQL WAMP - Couldn't connect to MSSQL 如何解决:PDOStatement :: execute()期望参数1为数组,在第64行的C:\\ wamp64 \\ www \\ invoiceTem01-Create.php中给出字符串 - How to fix : PDOStatement::execute() expects parameter 1 to be array, string given in C:\wamp64\www\invoiceTem01-Create.php on line 64
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM