SQL Server DNS

Was having problems getting my PDO to connect to the SQL Server with ODBC.
And to make matters worse I am on a windows LAN, the web server is a *nix box and my testing computer is M$. My DSN just was not right and wouldn’t play – my host string was off and any permutation I used wasn’t working. Looked at the PDO docs, the DSN docs in the manual, connectionstrings.com and no love.

I am most comfortable working with MySQL so getting the SQL Server to play had been frustrating in the extreme (hate when simple things are made hard – wanted to kick something). Turned out I needed to add my “instance” of the SQL server (not my word – bosses) to the host. So what did I finally come up with that works

PHP:

  1. $host = ’192.0.0.0\InstanceName’;
  2. $user = ‘user’;
  3. $pass = ‘xxxxxxxx’;
  4. $db = ‘test’;
  5.  
  6. $dbh = new PDO(“odbc:Driver={SQL Server};Server=$host;Database=$db;Uid=$user;Pwd=$pass;”);

* was it just me or was that an alphabet soup?

Commenting is disabled.