简体   繁体   English

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

[英]Cannot connect to mssql server with php

I want to connect to my mssql server through PHP but it says that there drivers cannot be found. 我想通过PHP连接到我的mssql服务器,但是它说找不到驱动程序。 This is my php-code: 这是我的php代码:

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

already added this line to php.ini: 已经将此行添加到php.ini中:

extension=php_pdo_sqlsrv_71_nts.dll
extension=php_sqlsrv_71_nts.dll

Can anybody help me? 有谁能够帮助我?

1: Settings related to your php.ini file: 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: Settings related to the dll files. 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: restart server 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”);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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