MSSQL and yii2

Please I want to use Microsoft(mssql 2012/2014) with my yii2 application instead of mysql. Please How do I go about it.

Install PDO, configure DSN then use it as usual.

How do I instal PDO

Depends which OS your server is running.

On Ubuntu > 16.04

curl | apt-key add -

curl > /etc/apt/sources.list.d/mssql-tools.list

curl > /etc/apt/sources.list.d/mssql-release.list

apt-get update

apt-get install mssql-tools

apt-get install unixodbc-dev

ln -sfn /opt/mssql-tools/bin/sqlcmd- /usr/bin/sqlcmd

ln -sfn /opt/mssql-tools/bin/bcp- /usr/bin/bcp

ACCEPT_EULA=Y apt-get install msodbcsql

apt-get install unixodbc-utf16

apt-get install unixodbc-dev-utf16

pecl install sqlsrv pdo_sqlsrv

echo "extension=/usr/lib/php/20151012/" >> /etc/php/7.0/apache2/php.ini

echo "extension=/usr/lib/php/20151012/" >> /etc/php/7.0/apache2/php.ini

echo "extension=/usr/lib/php/20151012/" >> /etc/php/7.0/cli/php.ini

echo "extension=/usr/lib/php/20151012/" >> /etc/php/7.0/cli/php.ini

My summary from:

I just started using this recently. It’s great to be able to access SQL server from Linux without needing to mess with FreeTDS, etc.

Windows 8.1

For Windows you can get it from

You have spent more than a day on this, when you could have done this.

That’s not productive.

Not for you.

Nor anyone else.


pdo for php version 7 is not working

Then find a version for 5.6. It was somewhere around.

Thanks a lot. Problem solved