D
D
Dmitry2014-12-09 15:11:38
Zend Framework
Dmitry, 2014-12-09 15:11:38

How to update records in a database with arbitrary information in Zend Framework 2?

How to edit records (multiple) in a database in a model in ZF2? Tried through

use Zend\Db\TableGateway\AbstractTableGateway;
use Zend\Db\Adapter\Adapter;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\Sql\Select;
use Zend\Db\Sql\Update;
...
$this->update(
                array('param' => '1'), // редактируемый столбец
                array('parent_id' => $parent_id) // условие
);
nothing happens and it's weird.
UPD 1:
This design works, i.e. updates the records in the database, but throws an error:
$update = $this->update(
    array('value' => '1'),
    array('parent_id' => $parent_id)
);
$this->updateWith($update);

And this is how everything works as it should:
$update = new Update();
$update->table($this->table);
$update->where(array('parent_id' => $parent_id));
$update->set(array('value' => '1'));
$this->updateWith($update);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2014-12-09
@another_dream

The actual solution to my question:

$update = new Update();
$update->table($this->table);
$update->where(array('parent_id' => $parent_id));
$update->set(array('value' => '1'));
$this->updateWith($update);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question