Ejemplo n.º 1
0
<?php

/**
 * Example of DataBase class used
 *
 * @package    Example
 * @author     Romain Laneuville <*****@*****.**>
 */
use classes\DataBase as DB;
require_once '\\utilities\\autoloader.php';
try {
    DB::beginTransaction();
    if (DB::exec('DELETE FROM table WHERE 1 = 1') > 1) {
        DB::rollBack();
    } else {
        DB::commit();
    }
} catch (\Throwable $t) {
    echo $e->getMessage() . PHP_EOL;
} finally {
    exit(0);
}
Ejemplo n.º 2
0
 /**
  * Save the entity EntityCollection in the database
  *
  * @param      Collection  $collection  OPTIONAL If a collection is passed, this collection becomes the
  *                                      EntityManager Collection DEFAULT null
  *
  * @return     bool        True if the entity collection has been saved, false otherwise
  */
 public function saveCollection($collection = null) : bool
 {
     if ($collection !== null) {
         $this->setEntityCollection($collection);
     }
     $currentEntity = $this->entity;
     $success = true;
     DB::beginTransaction();
     foreach ($this->entityCollection as $entity) {
         if (!$success) {
             break;
         }
         $this->setEntity($entity);
         $success = $this->saveEntity();
     }
     if ($success) {
         DB::commit();
     } else {
         DB::rollBack();
     }
     // restore the initial entity
     $this->entity = $currentEntity;
     return $success;
 }