From the same project as my last blog post, we had to connect a Laravel 5 web application to a SQL Server instance running on Azure. It took me awhile to get everything working well, so I want to share a few tips for anyone looking for something like that.

A quick Google search gives lots of good resources and once you find out the SQL Server connector in Ubuntu / Linux is actually called FreeTDS or Sybase (btw, Wikipedia has a nice article about why this name), you’re good to go with a few apt-get commands if you’re on Ubuntu:

sudo apt-get install freetds-common freetds-bin unixodbc php5-sybase

Great, but then you get this error:

SQLSTATE[01002] Adaptive Server connection failed (severity 9)

Oops! This happens because we’re trying to connect to an Azure server, so you can actually ignore this if you’re not getting this error.

Somewhere in the internet you discover you have to change the TDS protocol version to connect to Azure. Cool! You also discover you can do that in a configuration file. So, open up /etc/freetds/freetds.conf and change a few lines around:

        # TDS protocol version
        ;tds version = 4.2
        tds version = 8.0

Everything is great and life can move on!

Or, so you thought! Once you started handling dates in your models, all hell break loose and you start to get Carbon and Datetime issues everywhere. Don’t worry, the fix is simple again, now go to /etc/freetds/locales.conf and make it look like:

date format = %Y-%m-%d %I:%M:%S.%z

Now you can actually start working on something productive again!