Console App: Could not find DB driver

Hello everyone!

Need a help for understand what is wrong and fix it!

Yii version : 1.0.7

I try create a console application by instruction, all work done with simple actions.

When i try begin use DB i catch error:


2009/08/04 09:04:18 [error] [exception.CDbException] exception 'CDbException' with message 'CDbConnection failed to open the DB connection: could not find driver' in C:\WAPP\apache2\htdocs\yii\framework\db\CDbConnection.php:248

Stack trace:

#0 C:\WAPP\apache2\htdocs\yii\framework\db\CDbConnection.php(223): CDbConnection->open()

#1 C:\WAPP\apache2\htdocs\yii\framework\db\CDbConnection.php(202): CDbConnection->setActive(true)

#2 C:\WAPP\apache2\htdocs\yii\framework\base\CModule.php(353): CDbConnection->init()

#3 C:\WAPP\apache2\htdocs\yii\framework\base\CModule.php(91): CModule->getComponent('db')

#4 C:\WAPP\apache2\htdocs\seoportal\protected\commands\EmailCommand.php(7): CModule->__get('db')

#5 C:\WAPP\apache2\htdocs\yii\framework\console\CConsoleCommandRunner.php(62): EmailCommand->run(Array)

#6 C:\WAPP\apache2\htdocs\yii\framework\console\CConsoleApplication.php(88): CConsoleCommandRunner->run(Array)

#7 C:\WAPP\apache2\htdocs\yii\framework\base\CApplication.php(133): CConsoleApplication->processRequest()

#8 C:\WAPP\apache2\htdocs\seoportal\cli.php(10): CApplication->run()

#9 {main}

my cli.php:


<?php

// change the following paths if necessary

$yii=dirname(__FILE__).'/../yii/framework/yii.php';

$config=dirname(__FILE__).'/protected/config/console.php';

set_time_limit(1800);

// remove the following line when in production mode

defined('YII_DEBUG') or define('YII_DEBUG',true);


require_once($yii);

Yii::createConsoleApplication($config)->run();

my protected/config/console.php have components => db same with main php for web part(work fine with db)

piece of db :


'db'=>array(

            'connectionString'=>'pgsql:host=127.0.0.1 port=5432 dbname=eler0623',

            'username'=>'postgres',

            'password'=>'123',     

		),



my EmailCommand.php:




class EmailCommand extends CConsoleCommand

{

    public function run($args)

    {

//      CVarDumper::dump(SearchRequest::model()->getDbConnection());

        

        CVarDumper::dump(Yii::app()->db);


        

        echo 'DONE!'."\n";

    }

}



My command, executed from application base dir: php cli.php email

For prevent question about pdo look phpinfo():




PDO support	enabled

PDO drivers 	mysql, pgsql


pdo_mysql

PDO Driver for MySQL, client library version	5.0.45


pdo_pgsql

PDO Driver for PostgreSQL	enabled

PostgreSQL(libpq) Version 	8.3.1

Module version 	1.0.2

Revision 	$Id: pdo_pgsql.c,v 1.7.2.11.2.2 2007/12/31 07:20:10 sebastian Exp $ 



And Yes under console mode i see only pdo_mysql driver i check it:




       foreach(PDO::getAvailableDrivers() as $driver)

        {

            echo $driver."\n";

        }



On the test server (pre production) pgpdo is presented in console mode but i catch error from system: segmentation fault on the end of script.

I guess the console application does not use the same php ini as the webserver. Provide the proper ini file with the -c option




php -c path/to/ini <script file>



I think same as you but trying with php -c path/to/ini <script file> did not get luck.

And i have not any other php.ini files in my test system.

Oh I missed something obvious :)




'db'=>array(

            'connectionString'=>'pgsql:host=127.0.0.1 port=5432 dbname=eler0623',

            'username'=>'postgres',

            'password'=>'123',     

                ),






Your connection string is wrong. your forget ‘;’ between host, port and db name.




'db'=>array(

            'connectionString'=>'pgsql:host=127.0.0.1;port=5432;dbname=eler0623',

            'username'=>'postgres',

            'password'=>'123',     

                ),






something else that was the case on my system, I had multiple versions of PHP installed, the web server was correctly configured to load the right files, but the PHP CLI was using the old one, which did not recognize the DB drivers.

Using an absolute path to the php binary solved it.

:P