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 https://packages.microsoft.com/keys/microsoft.asc | apt-key add -

curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-tools.list

curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /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-13.0.1.0 /usr/bin/sqlcmd

ln -sfn /opt/mssql-tools/bin/bcp-13.0.1.0 /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/sqlsrv.so" >> /etc/php/7.0/apache2/php.ini

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

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

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



My summary from:

https://www.microsoft.com/en-us/sql-server/developer-get-started/php-ubuntu

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 https://github.com/Microsoft/msphpsql/releases

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.

THE PHP VERSION IS 5.6.15

pdo for php version 7 is not working

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

Thanks a lot. Problem solved