无法使用php连接到mssql服务器

时间:2019-07-03 06:23:17

标签: php sql-server pdo

我想通过PHP连接到我的mssql服务器,但是它说找不到驱动程序。 这是我的php代码:

$pdo = new PDO('mssql:host=SQL-Server;dbname=Test', 'User', 'Password')

已经将此行添加到php.ini中:

extension=php_pdo_sqlsrv_71_nts.dll
extension=php_sqlsrv_71_nts.dll

有人可以帮助我吗?

1 个答案:

答案 0 :(得分:-1)

1:与您的php.ini文件相关的设置:

a) Search mssql.secure_connection and put it on if it's off
b) remove comment from the dll extention php_mssql.dll

2:与dll文件相关的设置。

download a file name ntwdblib.dll from the internet. 
Note: (if path not known can be found in php.ini for variable extension_dir)

3:重新启动服务器

<?php    
$serverName = "serverName\\sqlexpress"; //serverName\instanceName
$connectionInfo = array( "Database"=>"dbName", "UID"=>"userName", "PWD"=>"password");
$conn = sqlsrv_connect( $serverName, $connectionInfo)
or die(“Couldn’t connect to SQL Server on $myServer”);

// select a database to work with
$selected = mssql_select_db($myDB, $dbhandle)
or die(“Couldn’t open database $myDB”);