Alun Rowe

ramblings about cars, tech, web development and more. BOTB Winner in 2010

Connect Codeigniter PHP7.3 to MSSQL

Wow, That’s a few hours of my life I won’t get back but, hopefully, you will after reading this article.

Due to some hideous compatibility issues and the obvious security issues associated with PHP5.6 I took the plunge and updated our server to Ubutntu 14 to Ubuntu 16 and installed PHP7.3.

So good so far.  The phpinfo() worked just fine but I had issues with connecting my Codeingiter App to the onsite MSSQL database.  When I say issues it just said mssql_connect not found.  Luckily I’d heard about this so I didn’t panic and got googling for a quick fix.

Well after a number of hours of chasing the wrong path I came across a VERY SIMPLE solution and here it all is laid out ready to roll!

Step 1: Follow ALL the instructions on this page.  Make sure you install the ODBC driver etc https://docs.microsoft.com/en-us/sql/connect/php/installation-tutorial-linux-mac?view=sql-server-ver15#installing-the-drivers-on-ubuntu-1604-1804-and-1810

Step 2.  Modify your Codeigniter database.php to reflect the following:

$db[‘mssql’][‘hostname’] = ‘sqlsrv:Server=SERVERNAME;Database=DBNAME’;
$db[‘mssql’][‘username’] = ‘USERNAME’;
$db[‘mssql’][‘password’] = ‘PASSWORD’;
$db[‘mssql’][‘database’] = ‘DBNAME’;
$db[‘mssql’][‘dbdriver’] = ‘pdo’;
$db[‘mssql’][‘dbprefix’] = ”;
$db[‘mssql’][‘pconnect’] = FALSE;
$db[‘mssql’][‘db_debug’] = TRUE;
$db[‘mssql’][‘cache_on’] = FALSE;
$db[‘mssql’][‘cachedir’] = ”;
$db[‘mssql’][‘char_set’] = ”;
$db[‘mssql’][‘dbcollat’] = ”;
$db[‘mssql’][‘swap_pre’] = ”;
$db[‘mssql’][‘autoinit’] = TRUE;

That SHOULD then work!  If not leave a message in the comments and lets see what we can find together.

PS I did have PHP 7.0 running according to PHPINFO but I quickly changed that to PHP7.3, use a phpinfo file to check your config!

Previous

FIXED: DNSMASQ not resolving .test domains for Valet

1 Comment

  1. I used this for swapping my PHP version::

    Disable PHP7.0 module on Apache:

    sudo a2dismod php7.0

    Now enable PHP7.3:

    sudo a2enmod php7.3

    Now restart Apache:

    sudo systemctl restart apache2

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Powered by WordPress & Theme by Anders Norén