title: Novice: How to properly set up db connection on zend framework?
body: <p>I'm pretty new to OOP and Zend. So far I'm trying to set up a db connection. I have this in my application.ini file:</p>
  
  <pre><code>resources.db.adapter = "PDO_MYSQL"
  resources.db.params.host = "localhost"
  resources.db.params.username = "root"
  resources.db.params.password = ""
  resources.db.params.dbname = "dbtest"
  resources.db.isDefaultTableAdapter = true
  </code></pre>
  
  <p>Supposedly I can access the db adapter everywhere with:</p>
  
  <pre><code>$db = Zend_Db_Table::getDefaultAdapter();
  </code></pre>
  
  <p>The problem is most guides assume you automatically know where to place that, but I honestly have no idea. What I'm doing so far is in my Index.php model I have a method:</p>
  
  <pre><code>public function getPosts()
  {
   $db = Zend_Db_Table::getDefaultAdapter();
   $sql = "SELECT * FROM posts";
   $result = $db-&gt;fetchAll($sql);
   return $result;
  }
  </code></pre>
  
  <p>With that one query it would be okay, but if I want to create more methods that hold my other queries each time I will have to call $db = Zend_Db_Table::getDefaultAdapter() so I'm sure I'm not doing this in an efficient way. I've already tried placing it in various __construct() and init() methods, but it wouldn't work. Where would I add the code without having to call it each time? Thanks.</p>