php5 ms sql server 2005

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
SBro
Forum Commoner
Posts: 98
Joined: Tue Sep 30, 2003 10:06 pm

php5 ms sql server 2005

Post 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.
Begby
Forum Regular
Posts: 575
Joined: Wed Dec 13, 2006 10:28 am

Post 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.
SBro
Forum Commoner
Posts: 98
Joined: Tue Sep 30, 2003 10:06 pm

Post by SBro »

Thanks, this was fixed very simply by placing square brackets around the dbname 8O
Post Reply