Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all articles
Browse latest Browse all 13329

Need help connecting PHP to MSSQL

$
0
0
I'm desperately trying to figure out how to connect PHP to MSSQL. I have PHP running on one server (SUSE Linux) and MSSQL running on another Windows server. I'm trying to figure out the best way to get them to connect.

I've installed the Windows MS SQL Linux Driver for SUSE
- found here: Download Microsoft® ODBC Driver 11 for SQL Server® - SUSE Linux CTP from Official Microsoft Download Center

I've also configured PHP so that it is setup with unixODBC.

Here is my odbc.ini file:
[MSSQLServer]
Driver = SQL Server Native Client 11.0
Database = <removed db name>
Server = <removed db server>
Port = <removed db port>


Here is my odbcinst.ini file:
[SQL Server Native Client 11.0]
Description=Microsoft SQL Server ODBC Driver V1.0 for Linux
Driver=/apps/msodbcsql-11.0.2260.0/lib64/libmsodbcsql-11.0.so.2260.0
UsageCount=1

Then in my php connection file I have the following:

putenv('ODBCSYSINI=/usr/local/etc');
putenv('ODBCINI=/usr/local/etc/odbc.ini');
$username = "<removed username>";
$password = "<removed password";
try {
$dbh = new PDO("odbc:MSSQLServer","$username","$password");
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $exception) {
echo 'Error: ' . $exception->getMessage();
exit;
}
echo var_dump($dbh);
unset($dbh);


When I run the above PHP I get the following error:

Error: SQLSTATE[IM004] SQLConnect: 0 [unixODBC][Driver Manager]Driver's SQLAllocHandle on SQL_HANDLE_HENV failed

Does, anyone have any idea what I'm doing wrong? I've been reading everything I can on the subject and I've been messing with this for over 2 weeks now trying to get it to work. I'm at my wits end! Please help! anyone!!

Viewing all articles
Browse latest Browse all 13329

Trending Articles