Page 1 of 1

php5 ms sql server 2005

Posted: Sun Sep 02, 2007 11:25 pm
by SBro
Hey guys,

I have previously made a connection from php on a linux server to sql server 2000 on a windows box using the freeTDS library, I had success in this and it worked fine. I'm now trying to do a similar thing except connect to sql server 2005. I can't get it to work on this configuration. I'm using pdo_dblib to connect, and have made the following sample file to test the connection. It should be noted that I've successfully connected remotely using Management Studio 2005, so the details I'm using are correct, and it appears that it's connecting initially because if I use an incorrect password for example I get a login error instead of the error below.

Code: Select all

try {
        $hostname = "***.***.**.**";
        $port = ****;
        $dbname = "***";
        $username = "***";
        $pw = "***";

        $pdo = new PDO("dblib:host=$hostname:$port;dbname=$dbname","$username","$pw");
} catch (PDOException $e) {
        echo "Failed to get DB handle: " . $e->getMessage() . "\n";
        exit;
}
The error I continue to get is
Failed to get DB handle: SQLSTATE[HY000] General SQL Server error: Check messages from the SQL Server. (severity 5)
Any help would be appreciated, thanks.

Posted: Mon Sep 03, 2007 8:01 pm
by Begby
Do you have access to the MS-SQL server console? If so there are a lot of handy logs and stuff on there where a more detailed message for this is probably stored. I would start there.

Posted: Mon Sep 03, 2007 8:09 pm
by SBro
Thanks, this was fixed very simply by placing square brackets around the dbname 8O