简体   繁体   中英

PHP PDO & SQL Server connection with dblib issues

I have experience about PDO but I was working with MySQL so far. I needed to work with PDO + SQL Server but seems something weird going on.

<?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. (severity 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. 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.

Thank you for your help and time in advance.

EDIT:

Problem is partially solved. Thanks to Uzay Teknoloji A.Ş. they've created SQL Server 2008 R2 database for me to test establishing SQL Server connection. The database I was trying to connect before was SQL Server 2000. It seems SQL Server 2000 doesn't support 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.

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