views:

429

answers:

2

My app is working from the web side of things.

I'd like to get the CLI working so that I can run unit tests and the such

Here's what I have for a test script:

$pthRoot = dirname(__FILE__);
define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/..'));
define('APPLICATION_ENV', 'development');
define('SERVER_ROLE', 'development');

set_include_path(implode(PATH_SEPARATOR, array(
    realpath(APPLICATION_PATH . '/../library') . PATH_SEPARATOR . realpath($pthRoot . '/../controllers')  
     . PATH_SEPARATOR . get_include_path()  
)));
date_default_timezone_set('America/Toronto'); 

require_once('Zend/Loader/Autoloader.php');  
$autoloader = Zend_Loader_Autoloader::getInstance();

require '../bootstrap.php';

require_once 'Zend/Application.php';
$application = new Zend_Application(
    APPLICATION_ENV,
    APPLICATION_PATH . '/configs/application.ini'
);
$_SERVER['SERVER_ROLE'] = 'development';
$bootstrap = $application->getBootstrap();
$bootstrap->runScript();

$db = Zend_Registry::get('db');
$sql = "select * from settings";
print_r($db->fetchAll($sql));

Unfortunately, I get an error at the get('db') line.

PHP Fatal error: Uncaught exception 'Zend_Db_Adapter_Exception' with message 'The mysql driver is not currently installed'

According to phpinfo from the command line, the mysql driver is running. What am I missing?

Thanks in advance.

+1  A: 

If you are using a MySQL Adapter with Zend Framework, you have two possibilities (I quote the doc) :

  • MySQL, using the pdo_mysql PHP extension
  • MySQL, using the mysqli PHP extension

Which one of those are you trying to use ?

If it's the first one, is the extension pdo_mysql activated for CLI ? (you can use "php -m" to get the list of extensions that are loaded)

If it's the second one, is the extension mysqli activated for CLI ?

It seems none of the two adapter are using the extension mysql (which is quite old) ; so, if this one appears, it's probably not really relevant.

With a bit of luck, it'll just be that "the right extension" is loaded in the php.ini file used for Web, and not in the one used for CLI...

Pascal MARTIN
It's using pdo_mysql. What I don't get is that I'm using the same config file for both situations, so shouldn't it be the same extensions that get loaded?
jeffkolez
Oh, I see the difference. It's the additional ini files scanned. Never encountered this before - the cli php isn't scanning the directory for extra ini files. I added those .so's to my php.ini and it worked. Thanks!
jeffkolez
OK, nice to know you got it working, and why it wasn't :-)
Pascal MARTIN
A: 

When running Zend Server, you have to source /etc/zce.rc to get the php cli working, if the command is not in your profile:

$ . /etc/zce.rc