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 7171573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:26:27+00:00 2026-05-28T15:26:27+00:00

I want my PHP Zend Application to get access to the database. Because the

  • 0

I want my PHP Zend Application to get access to the database.

Because the tasks are only two types: Get and Set a value from the database, I thought about simplifying it with universal methods.

It could look like this example.

namespace MyModule\Model;
use Zend\Db\Table\AbstractTable;

class MyTable extends AbstractTable
{
    protected $_name = 'tablename';

    public function getRow($selection)
    {
        $output = array();
        foreach($selection as $key => $value)
        {
            $row = $this->fetchRow($key ' = ' . $value);
            if (!$row) throw new Exception("error");
            array_merge($output, $row->toArray());
        }
        return $output;
    }

    public function addRow($values)
    {
        $this->insert($values);
    }

    public function updateRow($selection, $values)
    {
        foreach($selection as $key => $value)
        {
            $this->update($values, $key ' = ' . $value);
        }
    }

    public function deleteRow($selection)
    {
        foreach($selection as $key => $value)
        {
            $this->delete($key ' = ' . $value);
        }
    }
}

Are there any security or design arguments against this methods? I thought about making them global to access database like

 $row = database('mydatabase')->table('mytable')->getRow(array('id'=>'5'));

This solution would replace all the simple database models.

  • 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-28T15:26:28+00:00Added an answer on May 28, 2026 at 3:26 pm

    I think I’ll provide a simple example of how Zend_Db works, then you can demonstrate what you intend I’m not sure I completely understand.
    The Model

    // /application/Models/DbTable/MyTable.php
    <?php
    class Application_Model_DbTable_MyTable extends Zend_Db_Table_Abstract {
    
        //actual name of database table
        protected $_name = 'My_Table';
        //name of primary key
        protected $_primary = 'id';
    
    }
    

    And the controller

    // /application/controllers/MyController.php
    <?php
    class Mycontroller extends Zend_Controller_Action {
    
        public function init() {
    }
    
        public function indexAction() {
            //instantiate DbTable Model and execute FetchAll returns Rowset object
            //call ->toArray() for array to be returned: $model->fetchAll()->toArray();
            $model = new Application_Model_DbTable_MyTable();
            $model->fetchAll();
    }
    

    with just this simple model all of your CRUD functions are already available to your models and controllers.
    We create new methods or override existing methods to provide more control over our business logic.
    Most of us have need for more then simple CRUD functions.
    For example I have a delete function that requires a check for other data to be successful:

    // /application/Models/DbTable/Track.php
     public function deleteTrack($trackId) {
    
            $trackRowset = $this->find($trackId);
            $trackToGo = $trackRowset->current();
    
            $usedBy = $trackToGo->findDependentRowset('Application_Model_DbTable_Member');
            if (count($usedBy) == 0) {
    
                $where = $this->getAdapter()->quoteInto('trackid = ?', $trackId);
    
                $this->delete($where);
            } else {
                throw new Zend_Exception('Track is still assigned to member(s) and cannot be deleted.'
                    . "<br />" . 'Members: ' . count($usedBy));
            }
        }
    

    I hope this adds some clarity to our discussion.

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

Sidebar

Related Questions

I am testing a Zend application using PHPUnit. From time to time, I want
How can I write a sample console application with Zend? /Zend/Console/Getopt.php I just want
Part 1 I want to build a PHP Zend Framework application that users can
So I want to start logging in my Zend Framework application. I want to
I want to access to database mysql, I read that we can define the
I'm doing my first zend application, following the official user's guide, I set up
I am using PHP and Zend Framwwork for developing web apps, and i want
I want to manipulate Google Spreasheet in my application (in php), so, to do
I am working on a Zend Framework application with PHP. I have a form
I am writing unit test for zend project, I want to know <?php class

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.