简体   繁体   中英

How to connect Microsoft SQL Database using PHP

i am trying to connect mssql database using sqlsrv_connect() php function but it's always show below fatal error.

Fatal error: Call to undefined function sqlsrv_connect().

Code:

$server = 'xx.xxx.xxx.Xxx\sqlexpress';
$username = 'uname';
$password = 'password';
$database = 'testdb';


$connectionInfo = array( "Database"=>$database, "UID"=>$username, "PWD"=>$password);

$conn = sqlsrv_connect( $server, $connectionInfo);

if( $conn ) {
 echo "Connection established.<br />";
}else{
 echo "Connection could not be established.<br />";
 die( print_r( sqlsrv_errors(), true));
}

For this you have to download the associated driver.

The Microsoft SQL Server 2005 Driver for PHP allows PHP developers to access data in SQL Server 2005 and SQL Server 2008 databases. The driver includes support for Windows and SQL Server Authentication methods, transactions, parameter binding, streaming, metadata access, connection pooling, and error handling.

Check these links:

How to connect to MSSQL

Php Help Documnetation

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