Connecting to MSSQL from Laravel or PHP Via FREETDS

  1. Install freetds. freetds-0.91.112
     
     ./configure --with-tdsver=8.0
     make 
     sudo make install
     
     

Work through this link on the basics:
http://www.freetds.org/userguide/confirminstall.htm

Check if the `tsql is working fine.

tsql -S egServer50

conf file is located in /usr/local/etc/freetds.conf

Port is dynamic in most cases of MSSQL. You can find the port number for your instance using the below command.

tsql -LH CIVICSQL11

Open and append the code below to the freetds.conf file. sudo vi /usr/local/etc/freetds.conf


[CIVICSQL11]
host = CIVICSQL11
instance = T1
port = 59179
tds version = 8.0
client charset = UTF-8

TO TEST in PHP:


	?php
    	$conn = new PDO('dblib:dbname=Pinforce;host=CIVICSQL11:59179', 'username', 'pass');
?>

In laravel :


DB_HOST=CIVICSQL11
DB_PORT=PORTNUMBER
DB_DATABASE=DB_NAME
DB_USERNAME=USERNAME_HERE
DB_PASSWORD=PASSHERE