简体   繁体   English

CDbConnection无法打开数据库连接:在Yii中找不到驱动程序

[英]CDbConnection failed to open the DB connection: could not find driver in Yii

while trying to connect with mysql in yii framework it shows 在尝试与yii框架中的mysql连接时,它显示

"CDbConnection failed to open the DB connection: could not find driver " error “CDbConnection无法打开数据库连接:找不到驱动程序”错误

php code : php代码:

     'db'=>array(
        'class' => 'CDbConnection',
        'connectionString' => 'mysql:host=localhost:3306;dbname=testdrive',
        'emulatePrepare' => true,
        'username' => 'root',
        'password' => 'root',
        'charset' => 'utf8',
    ), 

my php drivers are already enabled , but it shows the same error 我的PHP驱动程序已经启用,但它显示相同的错误

Im using zend studio, zend server for this 我正在使用zend studio,zend服务器

how could i fix this? 我怎么能解决这个问题?

I am using Linux Mint..In my case I needed 我正在使用Linux Mint ..在我的情况下,我需要

apt-get install php5-mysql 

because I was moving my environment from Lampp to Apache + PHP + MySQL and I had to change a lot of things in the php.ini 因为我正在将我的环境从Lampp转移到Apache + PHP + MySQL,我不得不在php.ini中改变很多东西

Things you should check 你应该检查的事情

First you should check phpinfo() for the pdo_drivers installed. 首先,您应该检查安装的pdo_drivers的phpinfo()。

if u use IIS server , you should check php extensions installed or not. 如果您使用IIS服务器,您应该检查是否安装了php扩展。

check php.ini for extensions_dir is properly given 检查php.ini for extensions_dir是否正确给出

check you ext folder in php contains pdo_mysql dlls 检查你在php中的ext文件夹包含pdo_mysql dll

Some times the problem may occur due to zend server installation .You should check zend server is properly using the php extensions 有时可能由于zend服务器安装而出现问题。你应该检查zend服务器是否正确使用php扩展

After that check simple php-mysql connection using the following functions 之后使用以下函数检查简单的php-mysql连接

mysql_connect('localhost:3306','root','root');
mysql_select_db('testdrive');

If it works then go with Yii, Slim, Zend php-mysql connections 如果它工作,那么使用Yii,Slim,Zend php-mysql连接

I'm using Linux Ubuntu. 我正在使用Linux Ubuntu。

I have the same problem, but in my case i have to install the php-mysql. 我有同样的问题,但在我的情况下,我必须安装php-mysql。

sudo apt-get install php5-mysql

and restart the service 并重新启动该服务

sudo service apache2 restart

I hope thats help someone 我希望那可以帮助别人

try to install Sqlite drive by using following command in Ubuntu 尝试使用Ubuntu中的以下命令安装Sqlite驱动器

sudo apt-get install sqlite php5-sqlite

Now restart the Apache server by using following command 现在使用以下命令重新启动Apache服务器

service apache2 restart

this two step solve my problem. 这两步解决了我的问题。 hope it will solve other's also... 希望它能解决其他问题......

In my case, I also had to enable pdo_sqlite module and this solved the problem. 在我的情况下,我还必须启用pdo_sqlite模块,这解决了这个问题。 It was on a HOSTiq.com.ua hosting. 它是在HOSTiq.com.ua托管上。 I suppose it could save someone a few hours on searching. 我想它可以节省几个小时的搜索时间。

My solution was this: 我的解决方案是:

    cache' => array(
        'class' => 'system.caching.CDbCache',
        //'class' => 'system.caching.CFileCache',
        'connectionID'=>'db', // <<< THIS IS THE ISSUE
    ),

if connectionID is not set, db caching defaults to mysqli database in /protected/data directory which cannot be accessed if mysqli driver is not installed on system (common issue with dedicated servers, DO droplets, xampp/wamp...) 如果未设置connectionID,则db缓存默认为/ protected / data目录中的mysqli数据库,如果系统上未安装mysqli驱动程序,则无法访问该数据库(常见问题与专用服务器,DO drop,xampp / wamp ......)

or, you can disable db caching and enable fileCache instead. 或者,您可以禁用数据库缓存并启用fileCache。

In the current version of Yii you have a directory requirements . 在当前版本的Yii中,您有一个目录要求 It will launch Yii Requirement Checker and will show you what is missing. 它将启动Yii Requirement Checker并向您显示缺少的内容。

After that get you connection string right in main.php 之后,在main.php中获取连接字符串

'db'=>array(
            'connectionString' => 'mysql:host=deathstar;port=3306;dbname=database',
            'emulatePrepare' => true,
            'username' => 'user',
            'password' => 'pass',
            'charset' => 'utf8',
            'tablePrefix' => 'tbl_'
),

In my case it was something very silly. 就我而言,这是非常愚蠢的事情。 I forgot mysql: in 我忘记了mysql: in

'connectionString' => 'mysql:host=deathstar;port=3306;dbname=database'

If you don't get it only with this 如果你不这样做的话

apt-get install php-mysql

you can try this 你可以试试这个

apt-get install php-pear php5-dev libmysqlclient15-dev
pecl install pdo
pecl install pdo_mysql

I've found googling it was the only that works fine for me 我发现谷歌搜索它是唯一适合我的

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 yii CDbException:CDbConnection 无法打开数据库连接:找不到驱动程序 - yii CDbException: CDbConnection failed to open the DB connection: could not find driver Yii 1.1.x CDbHttpSession错误:CDbConnection无法打开数据库连接:找不到驱动程序 - Yii 1.1.x CDbHttpSession error: CDbConnection failed to open the DB connection: could not find driver CDbConnection无法打开数据库连接:在Yii中使用ORACLE数据库时找不到驱动程序 - CDbConnection failed to open the DB connection: could not find driver while using ORACLE database in Yii Yii CDbConnection无法打开数据库连接:找不到google cloud sql的驱动程序 - Yii CDbConnection failed to open the DB connection: could not find driver with google cloud sql 尝试生成模型类时,“ CDbConnection无法打开数据库连接:找不到驱动程序” - 'CDbConnection failed to open the DB connection: could not find driver' while trying to generate a model class CDbConnection无法打开数据库连接Yii - CDbConnection failed to open the DB connection Yii yiic:CDbConnection无法打开数据库连接 - yiic: CDbConnection failed to open the DB connection MySQL:CDbConnection 无法打开数据库连接 - MySQL: CDbConnection failed to open the DB connection CDbConnection无法打开数据库连接:无法打开数据库文件 - CDbConnection failed to open the DB connection: unable to open database file Echofish错误500“ CDbConnection无法打开数据库连接” - Echofish Error 500 “CDbConnection failed to open the DB connection”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM