title: Get db adapter from application object in Zend Framework 1
body: <p>I am working on an application written in Zend Framework.  I want to create a stand-alone API.  I'm copying over from <code>public/index.php</code>, and here is the key code on that:</p>
  
  <pre><code>/** Zend_Application */
  require_once 'Zend/Application.php';
  
  // Create application, bootstrap, and run
  $application = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini');
  $application-&gt;bootstrap()-&gt;run();
  </code></pre>
  
  <p>I have copied that over minus the <code>run()</code> directive, and now I'm trying to write db queries..  I've tried:</p>
  
  <pre><code>$application-&gt;_connection; //not declared, fails
  $application-&gt;_db; //same deal
  $application-&gt;select(); //same deal
  </code></pre>
  
  <p>I want to run things like:</p>
  
  <pre><code>$result = $application-&gt;_some_connection_object_but_where-&gt;query( .. );
  </code></pre>
  
  <p>Can you help me answer the "but where" part?  Thanks</p>
  
  <p>--EDITED INFO--</p>
  
  <p>Also, to answer the great response I had on this, I do have a file called <code>/application/Bootstrap.php</code> with a class called:</p>
  
  <pre><code>class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
  </code></pre>
  
  <p>and this method for connection:</p>
  
  <pre><code>protected function _initDb()
  {
      $appConfig = new Zend_Config_Ini('../application/configs/application.ini', APPLICATION_ENV);
      Zend_Registry::set('appConfig',$appConfig);
  
      $dbConfig = new Zend_Config_Ini('../application/configs/db.ini', APPLICATION_ENV);
      Zend_Registry::set('dbConfig',$dbConfig);
      $db = new Zend_Db_Adapter_Pdo_Mysql(array(
          'host' =&gt; $dbConfig-&gt;database-&gt;params-&gt;host,
          'username' =&gt; $dbConfig-&gt;database-&gt;params-&gt;username,
          'password' =&gt; $dbConfig-&gt;database-&gt;params-&gt;password,
          'dbname' =&gt; $dbConfig-&gt;database-&gt;params-&gt;dbname,
     ));
      $db-&gt;setFetchMode(Zend_Db::FETCH_ASSOC);
      $db-&gt;getConnection(); // force a connection... do not wait for 'lazy' connection binding later
      Zend_Registry::set('db',$db);
  
      Zend_Db_Table::setDefaultAdapter($db);
  
  }
  </code></pre>