-1

Problem in a few words When running a PHP script (precisely, an Yii 1.1 ConsoleCommand) that must connect to my sql server, I got

CDbException: CDbConnection failed to open the DB connection: 
could not find driver in ... /CDbConnection.php:399

I'm sure I have driver compiled and installed and php.ini configured.

Environment

$ php -version
PHP 7.0.13-0ubuntu0.16.04.1 (cli) ( NTS )

$  lsb_release  -d
Description:    Ubuntu 16.04.1 LTS

$ apachectl -V
Server version: Apache/2.4.18 (Ubuntu)

Yii DB config

"sql_server_db" => array (
        'class'                 => "CDbConnection",
        'connectionString'      => 'dblib:host=SQL-SERVER;dbname=at6_rp',
        'enableParamLogging'    => false,
        'username'              => '<hidden>',
        'password'              => '<hidden>',
        'charset'               => 'utf8',
    ),

I've an identical copy of my Yii 1 app running well on an other machine with an old Ubuntu 8 and php 5.2. So I think my connection string is right.

Yii code - point where throwed the error

See https://github.com/yiisoft/yii/blob/1.1.17/framework/db/CDbConnection.php#L382-L409

For documentation, I report here, step-by-step what I did to install the drivers

I followed instructions found here: https://github.com/Microsoft/msphpsql

Step 1: Install PHP extensions

Here i avoided installation of php7.0 because I already have it

sudo su
apt-get update
apt-get -y install php7.0-fpm php-pear php7.0-dev mcrypt php7.0-mcrypt php-mbstring php7.0-xml re2c gcc g++

Step 2: Install pre-requisites

sudo su 
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-release.list
exit
sudo apt-get update
sudo ACCEPT_EULA=Y apt-get install msodbcsql mssql-tools 
sudo apt-get install unixodbc-dev-utf16 unixodbc-utf16 odbcinst1debian2-utf16 

I didn't setup of apache, I already have it.

Step 4: Install the Microsoft PHP Drivers for SQL Server

sudo pecl install sqlsrv
sudo pecl install pdo_sqlsrv

Above rows installed the v4.0.8

Step 5: Add the Microsoft PHP Drivers for SQL Server to php.ini

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

I verified: these lines are both in apache2/php.ini and in cli/php.ini

Step 6: Restart Apache to load the new php.ini file

sudo service apache2 restart

Anyway: the problem is still here. When I run the php script I got

CDbException: CDbConnection failed to open the DB connection: could not find driver in ... cut .. /yii/framework/db/CDbConnection.php:399

UPDATE 1:

As suggested, I restarted php-fpm

sudo systemctl restart php7.0-fpm.service

No, errors, but the problem with connection is stille here

topher
  • 14,790
  • 7
  • 54
  • 70
realtebo
  • 23,922
  • 37
  • 112
  • 189
  • Have you restarted your php-fpm process? – yivi Feb 10 '17 at 12:45
  • I tried `sudo systemctl restart php7.0-fpm.service`. No errors, but no output. Anyway same problem ! – realtebo Feb 10 '17 at 12:47
  • 1
    Are you sure you've updated the correct php.ini? if memory serves correctly, FPM uses a different one than if mod_php is used. Check `` on a page on your server to make sure you've updated the right one. – apokryfos Feb 10 '17 at 12:54
  • Well, I see `/etc/php/7.0/apache2/php.ini`, so from web-side it looks ok, but I see reference to sqlsrv but not to pdo_sqlsrv ....and the pdo version is NEEDED by Yii – realtebo Feb 10 '17 at 13:06
  • @realtebo, you need to add the pdo reference as well. Can you confirm if sqlsrv and pdo_sqlsrv are indeed added? – meet-bhagdev Feb 13 '17 at 20:29

1 Answers1

0

Resolved with a simply ...

sudo apt install php7.0-sybase

No more configs to add, no restart required.

Found here: Linux - PHP 7.0 and MSSQL (Microsoft SQL) (but not is the accepted answer in that case)

Community
  • 1
  • 1
realtebo
  • 23,922
  • 37
  • 112
  • 189