2017-02-10 12:42
浏览 71

PHP 7.0 / Yii 1 / MS Sql Server 2008:PHP无法找到驱动程序

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.


$ 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


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

I followed instructions found here:

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 | apt-key add -
curl > /etc/apt/sources.list.d/mssql-release.list
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/" >> /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

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


As suggested, I restarted php-fpm

sudo systemctl restart php7.0-fpm.service

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

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doubi6669 2017-02-10 13:27

    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)

    点赞 打赏 评论

相关推荐 更多相似问题