简体   繁体   English

PHP PDO和SQL Server与dblib的连接问题

[英]PHP PDO & SQL Server connection with dblib issues

I have experience about PDO but I was working with MySQL so far. 我有关于PDO的经验,但是到目前为止我一直在使用MySQL。 I needed to work with PDO + SQL Server but seems something weird going on. 我需要使用PDO + SQL Server,但似乎有些奇怪。

<?php
$dsn = 'dblib:dbname=my_db;host=127.0.0.1'; //dbname and host is on different server, not localhost
$user = 'username';
$password = 'password';
try {
    $db = new PDO($dsn, $user, $password);
    $db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING );  
}
catch(PDOException $e) {  
    echo $e->getMessage();  
} 
?>

I'm getting following error; 我收到以下错误;

SQLSTATE[HY000] General SQL Server error: Check messages from the SQL Server. SQLSTATE [HY000] SQL Server的常规错误:检查来自SQL Server的消息。 (severity 5) (严重性5)

I'm really confused right now what is wrong with my code. 我现在真的很困惑我的代码出了什么问题。 Dblib is installed on the server, I didn't even make any queries and this code should work just fine. Dblib安装在服务器上,我什至没有进行任何查询,此代码应该可以正常工作。 Where ever I checked over the internet every time it is the same code. 每当我在互联网上检查过的地方,都是相同的代码。 That's why I'm sure that there is nothing wrong with my code. 这就是为什么我确定我的代码没有错。

I will be glad if anyone who has experience about it could help me out with it. 如果有任何经验的人可以帮助我,我将很高兴。

PS I'm aware of the fact that dblib is in experimental state still it should be able to establish a connection. PS我知道dblib仍处于实验状态这一事实,它仍然应该能够建立连接。

Thank you for your help and time in advance. 感谢您的帮助和提前的时间。

EDIT: 编辑:

Problem is partially solved. 问题已部分解决。 Thanks to Uzay Teknoloji A.Ş. 感谢Uzay TeknolojiA.Ş。 they've created SQL Server 2008 R2 database for me to test establishing SQL Server connection. 他们为我创建了SQL Server 2008 R2数据库,以测试建立SQL Server连接的过程。 The database I was trying to connect before was SQL Server 2000. It seems SQL Server 2000 doesn't support dblib. 我之前尝试连接的数据库是SQL Server2000。似乎SQL Server 2000不支持dblib。

I would like to close the question. 我想结束这个问题。 As I wrote on my question problem was with PHP dblib not supporting SQL 2000 so I couldn't connect. 正如我在问题中所写的那样,PHP dblib不支持SQL 2000,因此无法连接。

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

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