Results 1 to 1 of 1
  1. #1
    Join Date
    Mar 2013
    Posts
    1

    Unanswered: Need help connecting PHP to MSSQL

    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
    - found here: Download Microsoft® ODBC Driver 11 for SQL Server® from Official Microsoft Download Center

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

    Here is my odbc.ini file:
    [MSSQL]
    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=/usr/local/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:MSSQL","$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!!
    Last edited by stingrayg; 03-26-13 at 15:51.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •