Update on Zend 2

Asked

Viewed 234 times

4

I’m studying Zend Framework 2 and I’m needing a hand to do an update on two tables that are related. Come on.

I have the table entries with the fields:

id_entrada       id_notafiscal

and in the rating table the fields:

id_notafiscal cod_notafiscal

I summarized the amount of fields to facilitate.

I need to update the invoice table and I can even use the query:

UPDATE notafiscal  en
INNER  JOIN entrada e   
ON e.id_notafiscal = en.id_notafiscal
and  id_entrada='2014-02-24'
SET cod_notafiscal=1 

How to do this using Zend 2?

To facilitate a little more I will post the code I use to make a select

between several tables.

public function find($id)
    {
        $id  = (int)$id;   
        $sql= $this->tableGateway->select(function (Select $select) use ($id) {
               $select->join('enotafiscal','entrada.id_notafiscal=enotafiscal.id_notafiscal','cod_notafiscal','left');
                $select->join('fornecedor','entrada.id_fornec=fornecedor.id_fornec','desc_forn','left');
                $select->join('produtos','entrada.id_produto=produtos.id_produto','desc_produto','left');
                $select->where(array ('id_entrada' => $id));
       });

       $row =$sql->current();

        if (!$row){
            throw new \Exception("Não foi encontrado entrada com o  id = {$id}");
        }
            return $row;
    }

It is possible to do such a thing using Zend’s Tablegateway class?

  • Some feedback?

  • Nothing. I’m still trying to figure it out.

  • I did a search and read on a Stackoverflow topic that the tablegateway class is for data from a single table. http://stackoverflow.com/questions/18157695/zf2-database-transactions-with-updating-multiple-tables

2 answers

1

Try this:

$sql = $this->tableGateway->getAdapter()
    ->createStatement(
        'UPDATE notafiscal  en
INNER  JOIN entrada e   
ON e.id_notafiscal = en.id_notafiscal
and  id_entrada=' . $idEntrada . '
SET cod_notafiscal= ' . $notaCod 
    );

$resultSet->initialize( $sql->execute() );

echo $resultSet->count();
  • I tested based on your post, but found that there is no reference to "createStatement".

0

  • 1

    How would he use this class? Dig a little deeper into his answer.

  • I already searched in the documentation some application example but found nothing about joins in the update.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.