Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3460768
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:16:12+00:00 2026-05-18T10:16:12+00:00

I’m pretty new to OOP and Zend. So far I’m trying to set up

  • 0

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:

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

Supposedly I can access the db adapter everywhere with:

$db = Zend_Db_Table::getDefaultAdapter();

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:

public function getPosts()
{
 $db = Zend_Db_Table::getDefaultAdapter();
 $sql = "SELECT * FROM posts";
 $result = $db->fetchAll($sql);
 return $result;
}

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T10:16:12+00:00Added an answer on May 18, 2026 at 10:16 am

    An easy way to run your queries would be to create a class for each of your tables that extends Zend_Db_Table_Abstract which would provide you some handy methods to help you get your stuff from your database.

    While using this method you will be able to call your table content through

    $postsTable = new Model_Db_Tables_Posts() // Assuming you put your class post in the folders models/db/tables/
    $posts = $postsTable->fetchAll();
    

    for a more specific post you could also fetch it by id using

    $singlePost = $postsTable->find(1); // Assuming the id of the post you want is 1
    

    And then for creating new entries you could go with

    $data = array('title' => 'Some title', 'content' => 'Some Content') // where the key is the table field and the value is the value you want to insert
    $newId = $postsTable->insert($data);
    

    And for updating

    $data = array('title' => 'Some title', 'content' => 'Some Content')
    $db = $postsTable->getAdapter();
    $where = $db->quoteInto('id = ?', $id); // quoteInto is used to escape unwanted chars in your query, not really usefull for integers, but still a good habit to have
    $postsTable->update($data, $where);
    

    Hope this helps you a bit, you could find more info in the official ZF doc at http://framework.zend.com/manual/fr/zend.db.table.html and http://framework.zend.com/manual/fr/zend.db.table.row.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I want use html5's new tag to play a wav file (currently only supported
I am trying to render a haml file in a javascript response like so:
This could be a duplicate question, but I have no idea what search terms
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.