How to get results information when updating mysql table with Doctrine ORM in symfony 1.4

I am developing Symfony 1.4 and using Doctrine ORM. After building the schema and models, I have several classes for working with the database. I can also use Doctrine_query .... The only thing I can not understand:

I need to update the table.

Doctrine_Query::create()->update('table')->.....->execute(). 

or

 $tbl = new Table(); $tbl->assignIdentifier($id); if($tbl->load()){ $tbl->setFieldname('value'); $tbl->save(); } 

How can I understand if this was a successful query result or not? and how many rows have been updated.

ps the same question applies to the delete operation.

+4
source share
2 answers

Everything in the document for update and delete .

When executing DQL UPDATE and DELETE queries, query execution returns the number of rows affected.

See examples:

 $q = Doctrine_Query::create() ->update('Account') ->set('amount', 'amount + 200') ->where('id > 200'); $rows = $q->execute(); echo $rows; 
 $q = Doctrine_Query::create() ->delete('Account a') ->where('a.id > 3'); $rows = $q->execute(); echo $rows; 

This is due to DQL (when you use doctrine queries). But I think that ->save() will return the current object or true / false, as @PLB commented.

+7
source
 $statement = $this->entityManager->getConnection()->prepare($sql); $statement->execute(); // the counter of rows which are updated $counter = $statement->rowCount(); 

It works very well with doctrine 2 in the symfony 2 project

+1
source

All Articles