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!
AlunR
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
don britton
Hi Alun, when you were able to get Codeigniter to connect to MSSQL were you using CI3 or CI4? I have an upcoming project that would be similar in nature but would really like to use CI4 if at all possible.
Thanks!
AlunR
It was CI3 in this instance.
CI4 supports MSSQL but you need the SQLSRV driver. I believe this is what you would need.
https://github.com/Microsoft/msphpsql/releases/tag/v5.10.0
CI4 doesn’t have a lot of support a the moment so it’s worth looking at the Laravel community as Laravel uses SQLSRV for it’s connections to MSSQL
I’ve completely moved to Laravel these days bar a few legacy apps so can’t help a lot more I’m afraid.