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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:45:35+00:00 2026-05-23T22:45:35+00:00

I got model in Zend Framework what extends Zend_Db_Table where $this->_name = ‘tableA’ .

  • 0

I got model in Zend Framework what extends Zend_Db_Table where $this->_name = 'tableA'.

It is very nice how long I doing insert(), update(), or delete(). How I can realize updating main table based on value from another table.. ?

In raw SQL query it could looks like this:

UPDATE tableA SET fieldA = tableB.newValue
FROM tableB
WHERE tableA.someValue = tableB.someIndex // it will be complicate manipulation
  AND tableA.index = .....

how I can build params for update() method:

parent::update( $data, $where );
  • 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-23T22:45:36+00:00Added an answer on May 23, 2026 at 10:45 pm

    There are no possible combinations of how to build params for the parent::update() method to get that final update query. The reason is because the Db Table update method just passes along your $data and $where variables to the Db Adapter’s update method. The adapter’s update method leaves no room for attaching additional information. You can’t hack params at all

    If you can’t use table relationships with cascade update. Your best bet will be to extend the Db Adapter and create a new method to handle these types of updates. This should work.

    /** 
     * Add this method to you custom adapter
     * Direct copy of update method with integration of $from
     * @see Zend_Db_Adapter_Abstract::update
     **/
    public function updateFrom($table, $from, array $bind, $where = '')
    {
        /**
         * Build "col = ?" pairs for the statement,
         * except for Zend_Db_Expr which is treated literally.
         */
        $set = array();
        $i = 0;
        foreach ($bind as $col => $val) {
            if ($val instanceof Zend_Db_Expr) {
                $val = $val->__toString();
                unset($bind[$col]);
            } else {
                if ($this->supportsParameters('positional')) {
                    $val = '?';
                } else {
                    if ($this->supportsParameters('named')) {
                        unset($bind[$col]);
                        $bind[':col'.$i] = $val;
                        $val = ':col'.$i;
                        $i++;
                    } else {
                        /** @see Zend_Db_Adapter_Exception */
                        require_once 'Zend/Db/Adapter/Exception.php';
                        throw new Zend_Db_Adapter_Exception(get_class($this) ." doesn't support positional or named binding");
                    }
                }
            }
            // Reason #1 you can't hack into $data array to pass reference to a table
            $set[] = $this->quoteIdentifier($col, true) . ' = ' . $val;
        }
    
        $where = $this->_whereExpr($where);
    
        /**
         * Build the UPDATE statement
         */
        $sql = "UPDATE "
             . $this->quoteIdentifier($table, true)
             . ' SET ' . implode(', ', $set)
             . ' FROM ' . $this->quoteIdentifier($from, true) // My only edit
             . (($where) ? " WHERE $where" : ''); // Reason #2 no room in where clause
    
        /**
         * Execute the statement and return the number of affected rows
         */
        if ($this->supportsParameters('positional')) {
            $stmt = $this->query($sql, array_values($bind));
        } else {
            $stmt = $this->query($sql, $bind);
        }
        $result = $stmt->rowCount();
        return $result;
    }
    
    /** Add this to your extended Zend_Db_Table **/
    public function update(array $data, $where)
    {
        $tableSpec = ($this->_schema ? $this->_schema . '.' : '') . $this->_name;
        $from      = 'schema.name'; // Get from table name 
        return $this->_db->updateFrom($tableSpec, $from, $data, $where);
    }
    

    Note: I didn’t test this out, but I am pretty confident it will work as expected. If you have any problems, just let me know. Because I copied the adapter’s update method, I went ahead and added notes of the reasons why you can’t hack those params.

    EDIT
    I almost forgot to mention. Every adapter is unique so you will have to check with your adapters update method. I just copied from Zend_Db_Abstract.

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

Sidebar

Related Questions

I've got a zend framework model: class User extends Zend_Db_Table_Abstract { protected $_name =
I'm new to zend framework so maybe this question is stupid.. I've got a
I've got a model like this def upload_location(instance, filename): return 'validate/%s/builds/%s' % (get_current_user(), filename)
Say I've got a domain model created from C# classes like this: public class
I'm tryin to learn few things about Zend Framework and I got stucked on
I got a model like this: public class MainModel { public string Id {get;set;}
I've got a model like this: class Thing(models.Model): property1 = models.IntegerField() property2 = models.IntegerField()
I've got a model like this: public class ParentViewModel { public class ChildViewModel {
I'm sing the Data Mapper Pattern in Zend Framework. This works well so far,
I've got a model that's migrating sucessfully but is taking 15-20 seconds. (Obviously this

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.