The connection string to use with PHP, dblib and SQL Server

If you are trying to connect to an SQL Server database with the dblib drivers for PDO, this is the correct connection string to use:

new PDO('dblib:host='.$host.';dbname='.$database, $this->user, $this->password);

You can also specify the encoding with charset=UTF-8 or charset=ISO-8859-1 if necessary.

Be aware that dblib is incredibly buggy and that it does not support unicode or transactions. I have also encountered important other bugs, such as being unable to use ERRMODE_EXCEPTION. However, there are not that many alternatives if you want have to connect to SQL Server from PHP on Linux

One comment on “The connection string to use with PHP, dblib and SQL Server

Leave a Reply

Your email address will not be published. Required fields are marked *

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax