简体   繁体   中英

How to connect to MSSQL DB with wamp64

I'm using wamp64 as localhost for programming my php code.
But now I got asked to connect to a MSSQL DB.
I searched for answers on how to do it and found sqlsrv_connect() function.
When I call this function I get this error:

Uncaught Error: Call to undefined function sqlsrv_connect() in C:\\wamp64\\

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

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 :

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'

I solved it ~ PHP Version 7.2.4

pdo_sqlsrv : 5.3.0+11108

1.download the proper version sqlsrv and sqlsrv pdo

2.put it into XAMPP\\PHP\\ext folder

3.after that write the line into php.ini > module setting

extension=php_pdo_sqlsrv_72_ts.dll

extension=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

  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

(mine is Command Line Utilities 11 for SQL Server® X86)

6.fire the test.php again everything works!

I followed @SayedMohdAli's steps and Got this error:

PHP Startup: Unable to load dynamic library 'sqlsrv_72_nts'

I changed the name from 'sqlsrv_72_nts' to 'sqlsrv_72_ts' and It worked.

@SayedMohdAli thanks for helping me with this getting started. Solved it with your help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM