尽管已安装和启用驱动程序,但PHP(PDO)的SQL Server访问无法正常工作

我正在尝试访问SQL Server。</ p>

更新:作为回应 对于Clive的评论,我也尝试重新安装本机ODBC驱动程序,但没有改变。</ p>

我已经检查了所有可以找到的问题,一切似乎都是有序的。 我的服务器详细信息:</ p>

PHP 5.4(通过Plesk管理)

SQL Server 2008 R2 SP2

Windows Server 2008 R2 </ p>

PDO的最新mssql驱动程序位于EXT目录中,并在php.ini中引用:</ p>

  extension = php_sqlsrv_54_nts.dll 
extension = php_pdo_sqlsrv_54_nts.dll
</ code> < / pre>

PHPINFO()</ code>提供以下内容:</ p>

  PDO驱动程序:mysql,sqlite,sqlsrv 
pdo_sqlsrv支持: enabled
sqlsrv support:enabled
</ code> </ pre>

我的连接字符串如下所示:</ p>

  $ DSN =“sqlsrv:  Server = myDbServer,1433; database = my-dbname“; 
$ PdoOptions = array(
PDO :: ATTR_ERRMODE =&gt; PDO :: ERRMODE_EXCEPTION,
PDO :: ATTR_DEFAULT_FETCH_MODE =&gt; PDO :: FETCH_ASSOC
) ;
$ sparklyGenericPdoObj =新的PDO($ DSN,'myUsername','myPasswurde',$ PdoOptions);
</ code> </ pre>

但是这只会给我以下错误 链接 - 以迂回的方式 - 到我已经安装的驱动程序(我检查了版本 数字):</ p>


PHP致命错误:未捕获的异常'PDOException',带有消息
'SQLSTATE [IMSSP]:此扩展名需要Microsoft SQL Server

2012hown Native Client ODBC驱动程序与SQL Server通信。 访问以下URL以下载x86的Microsoft SQL Server 2012 Native
Client ODBC驱动程序:
http://go.microsoft.com/fwlink/?LinkId=163712 '</ p>
</ blockquote>

在此主题上(报告完全相同的错误) 因为我是一个解决方案,它说你可以通过查找我在PHPINFO中提到的项目来确认安装驱动程序:没有连接到Sql Server 2012 !</ p>

非常感谢任何帮助!</ p>
</ div >

展开原文

原文

I am trying to access an SQL Server.

UPDATE: In response to Clive's comments below I have also tried reinstalling the native ODBC driver but no change.

I've checked over all the questions I can find on this and everything seems to be in order. My server details:

PHP 5.4 (Managed via Plesk)
SQL Server 2008 R2 SP2
Windows Server 2008 R2

The latest mssql drivers for PDO are in the EXT directory and referenced in php.ini:

extension=php_sqlsrv_54_nts.dll
extension=php_pdo_sqlsrv_54_nts.dll

PHPINFO() gives the following:

PDO Drivers: mysql, sqlite, sqlsrv
pdo_sqlsrv support: enabled
sqlsrv support:  enabled

My connection string looks like this:

$DSN = "sqlsrv:Server=myDbServer,1433;database=my-dbname";
$PdoOptions = array(
    PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
    PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
);
$sparklyGenericPdoObj = new PDO($DSN,'myUsername','myPasswurde', $PdoOptions);

But that just gives me the following error which links - in a roundabout way - to the drivers I already have installed (I've checked the version numbers):

PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[IMSSP]: This extension requires the Microsoft SQL Server 2012 Native Client ODBC Driver to communicate with SQL Server. Access the following URL to download the Microsoft SQL Server 2012 Native Client ODBC driver for x86: http://go.microsoft.com/fwlink/?LinkId=163712'

On this thread (reporting exactly the same error as me) is a solution which says that you can confirm the driver is installed by looking for the items I've mentioned above in PHPINFO: Not getting connected to Sql Server 2012!

Any help would be much appreciated!

php
dounianluo0086
dounianluo0086 然而,一个红旗是它要求SQLServer2012驱动程序,但我安装了SQLServer2008R2(我知道它们是同一代但仍然看起来很奇怪?)
接近 6 年之前 回复
dongmei9020
dongmei9020 啊道歉-我对PHP不太熟悉所以假设它们也被称为驱动程序。已经为服务器安装了ODBC,OLEDB等驱动程序。SQLServer数据库正在运行许多其他数据库,这些数据库通过许多不同的语言访问,没有任何问题(.NET,ASP.NET,VBscript)以及通过本机ODBC驱动程序找到的MySQLWorkBench访问。这是我第一次尝试通过PHP访问它。
接近 6 年之前 回复
dongxin0031
dongxin0031 这是一个PHP扩展...你需要安装SQLserverodbc驱动程序。完全不同的东西
接近 6 年之前 回复
dongquqiao2010
dongquqiao2010 谢谢克莱夫。当我看到丢失的驱动程序时,我认为驱动可能会丢失所以我确保驱动程序没有丢失,如上面的评论:PDO的最新mssql驱动程序在EXT目录中并在php.ini中引用:扩展名=php_sqlsrv_54_nts.dll扩展名=php_pdo_sqlsrv_54_nts.dll
接近 6 年之前 回复
doushi5913
doushi5913 错误说你错过了一个驱动程序-尝试安装该驱动程序
接近 6 年之前 回复

3个回答

Although it is a fairly old post, I've decided that it would be better to place my answer here instead of creating an other question...

after 3 weeks of research all over the Web and testing a lot of hypothesis around php installation, php code and drivers installation, I finally found the solution to this question.

THE PROBLEM:

I have an app that is installed on WIN SERVER 2012 SP2 and running under IIS. The development of this app is made on a WIN 7 SP1 and running under 32-bit XAMPP 3.2.2. All of these are running PHP 5.6.

Everything is working fine on the server but I keep having this message when executed locally on XAMPP:

This extension requires the Microsoft ODBC Driver 11 for SQL Server to communicate with SQL Server

Even though I've installed this driver many times (with other php drivers found here, configure my php.ini to load php_sqlsrv_56_ts.dll and php_pdo_sqlsrv_56_ts.dll), it keeps returning me the same message...

The PDO command I've used to connect to distant MSSQL Server was:

$db = new PDO("sqlsrv:server=192.168.165.XXX;Database=testDB;", "userName", "passWord");

I have tried other drivers and it worked fairly well with ODBC driver;

$db = new PDO("odbc:Driver={SQL Server};Server=192.168.165.XXX;Database=testDB;", "userName", "passWord");

but I've found that there was some limitations with the later driver that I didn't experience with sqlsrv on the PROD server so I decided to push a little bit more my research to find a way to implement sqlsrv on my local machine...

THE INVESTIGATION:

Before connecting with PHP, I've tried to create System DSN (Data Source Name), with the ODBC Source Administrator (ODBCSA) application and test connection from there before trying to connect with my application. Something pretty strange I have discovered with Win7, is that there are two different ODBCSA applications.

The 32-bit version of the Odbcad32.exe file is located in the %systemdrive%\Windows\SysWoW64 folder.

The 64-bit version of the Odbcad32.exe file is located in the %systemdrive%\Windows\System32 folder.

The 32-bit version of the ODBC Administrator tool displays 32-bit system DSNs, 32-bit user DSNs, and 64-bit user DSNs.

The 64-bit version of the ODBC Administrator tool displays 64-bit system DSNs, 32-bit user DSNs, and 64-bit user DSNs

Just to make sure what ODBCA your are using, check in Task manager under odbcad32.exe, if you see *32 on its right, that means its the 32-bit version.

At first, I executed the 64-bit ODBCSA, created DSN using the brand newly installed ODBC Driver 11, called ODBC_11_64 and test the connection using the ODBCSA. All worked fine. When I tested my code I received an other error message:

The specified DSN contains an architecture mismatch between the Driver and Application

Ok then, I tried to create an new DSN using the 32-bit ODBCSA. It was strange at first, when I've discovered that there was no version number aside some driver names and I received this error from the ODBCSA:

The setup routines for the ODBC Driver 11 for SQL Server could not be found. Please reinstall the driver.

and an other message:

Component not found in the registry

It was obvious that there was an installation problem and the later message point me in the right direction, the Registry...

Starting regedit as admin, I've found that all 64-bit ODBC drivers can be found here: HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI

All 32-bit ODBC drivers can be found here: HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\ODBC\ODBCINST.INI

While trying to access the 64-bit key (\ODBC Driver 11 for SQL Server), I was able to display key values but when I tried to access the 32-bit key, I received this message:

Error Opening Key, ODBC Driver 11 for SQL Server Driver cannot be opened. An error is preventing this key from being opened. Details: Access is denied.

THE SOLUTION:

By right clicking on the 32-bit faulty key I was able to access permission interface. I was then able to add my username (I could also add a group) and granted full Control on the registry key.

I then came back to creating an new DSN using the 32-bit ODBCSA and ODBC Driver 11 for SQL Server, tested the connection with SUCCESS! :-)

I when back to my application and found that I was able to access the distant MSSQL SERVER using sqlsrv, on my local machine.

All along it was the driver installation package that was faulty! I should had install permissions to SYSTEM, users and administrators to the key has it did with the 64-bit registry key for this driver.

It was a pretty long story but I thought it was worth it, since a lot of persons tried to solve this complex problem, going in many different directions without success. Its also my contribution to all of you, who failed to find the solution but helped me in my investigation ;-)



最后,我通过从这里安装“Microsoft®SQLServer®2012SP1命令行实用程序”解决了这个问题(SqlCmdLnUtils.msi) :</ p>

http:/ /www.microsoft.com/en-in/download/details.aspx?id=35580 </ p>

不知道为什么会这样,但确实如此。</ p> \ n </ div>

展开原文

原文

In the end I solved this by installing the "Microsoft® SQL Server® 2012 SP1 Command Line Utilities" from here (SqlCmdLnUtils.msi):

http://www.microsoft.com/en-in/download/details.aspx?id=35580

No idea why this worked but there it is.



我喜欢php.ini中的一些配置但注意到了; </ p>

 ;  extension = odbc 
; extension = pdo_mysql
; extension = pdo_oci
; extension = pdo_odbc
</ code> </ pre>

删除“;”之前,重启服务,它是 工作!</ p>
</ div>

展开原文

原文

i have fond some config in php.ini but was noted;

;extension=odbc
;extension=pdo_mysql
;extension=pdo_oci
;extension=pdo_odbc

remove “;” before, restart service, and it is worked!

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐