Organizational Research By

Surprising Reserch Topic

get db adapter from application object in zend framework 1

get db adapter from application object in zend framework 1  using -'php,zend-framework,pdo,zend-db'

I am working on an application written in Zend Framework.  I want to create a stand-alone API.  I'm copying over from public/index.php, and here is the key code on that:

/** Zend_Application */
require_once 'Zend/Application.php';

// Create application, bootstrap, and run
$application = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini');

I have copied that over minus the run() directive, and now I'm trying to write db queries..  I've tried:

$application->_connection; //not declared, fails
$application->_db; //same deal
$application->select(); //same deal

I want to run things like:

$result = $application->_some_connection_object_but_where->query( .. );

Can you help me answer the "but where" part?  Thanks


Also, to answer the great response I had on this, I do have a file called /application/Bootstrap.php with a class called:

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap

and this method for connection:

protected function _initDb()
    $appConfig = new Zend_Config_Ini('../application/configs/application.ini', APPLICATION_ENV);

    $dbConfig = new Zend_Config_Ini('../application/configs/db.ini', APPLICATION_ENV);
    $db = new Zend_Db_Adapter_Pdo_Mysql(array(
        'host' => $dbConfig->database->params->host,
        'username' => $dbConfig->database->params->username,
        'password' => $dbConfig->database->params->password,
        'dbname' => $dbConfig->database->params->dbname,
    $db->getConnection(); // force a connection... do not wait for 'lazy' connection binding later




asked Oct 23, 2015 by sameer rathore
0 votes

Related Hot Questions

1 Answer

0 votes
answered Oct 23, 2015 by 20shahi