PHP MS SQL connection error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • darksteel21
    New Member
    • Jul 2008
    • 36

    PHP MS SQL connection error

    Hi All,

    i am trying to connect to a MS SQL Server using PHP on a Sun Solaris server. Currently I am using FreeTDS in connecting PHP to MsSQL. But i am having this error message:
    Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server:

    Can anyone help me.

    Thanks,

    Mark Tan
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    do you get an SQLSTATE error code with that? you could try to connect via PDO, that normally throws more descriptive errors.

    Comment

    • darksteel21
      New Member
      • Jul 2008
      • 36

      #3
      I guess my current PHP was not compiled with PDO support. And i am not familiar with PDO. I've succesfully installed FreeTDS on our Solaris server and i could connect in MSSQL server using FreeTDS with these commands :
      /usr/local/freetds/bin/tsql -S <ip of our MS SQL server> -U <User SQL> -P<Password>
      But when i try to connect using a php script :
      $con = mssql_connect([server], [username], [password]") or die("can't connect to MS SQL Server Error: " . mssql_get_last_ message());
      i am having these errors : Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server:
      i already recompiled my php with :
      --with-mssql
      what seems to be the problem?did i overlooked some php configurations and settings?

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        I guess my current PHP was not compiled with PDO support.
        which PHP version do you have?

        without a better error message I cannot really tell, maybe you can get a clue from the mssql settings in php.ini. I can imagine that you have to tell PHP to use FreeTDS. on the other hand side, if you have PHP 5.2+, PHP has PDO support by default and PDO does connect to MSSQL (given the MSSQL/DBLIB Driver is installed)

        EDIT: read the 3rd user comment here, it seems to deal with your issue.
        Last edited by Dormilich; Dec 29 '10, 09:22 AM.

        Comment

        • darksteel21
          New Member
          • Jul 2008
          • 36

          #5
          Oh i see... I am using PHP 5.1 and already told PHP to use FreeTDS with : --with-mssql=/usr/local/freetds configuration, if i upgrade my current PHP there might be a lot of changes and affected web apps on our porduction server. I'll try to look at the PDO. But why theres a notification on (http://www.php.net/manual/en/ref.pdo-dblib.php) php.net saying :
          WARNING
          This extension is EXPERIMENTAL. The behaviour of this extension including the names of its functions and any other documentation surrounding this extension may change without notice in a future release of PHP. This extension should be used at your own risk.

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            further down they recommend using the DBLIB driver for MS SQL.

            Comment

            Working...