Update in Zend 2

4

I'm studying Zend Framework 2 and am 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 fiscal_notes table the fields:

id_notafiscal cod_notafiscal

I have summarized the number of fields to facilitate.

I need to update the invoice table and even get 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 that I use to make a select

between multiple 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;
    }

Is it possible to do this using the Zend TableGateway class?

    
asked by anonymous 24.02.2014 / 23:08

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();
    
27.02.2014 / 16:05
0

zf2 has a class similar to the one you are using to make a select.

link

    
27.02.2014 / 19:23