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
 /**
  * Create a table based on the entity ini conf file
  *
  * @return     bool  True if the table is created else false
  */
 private function createTable() : bool
 {
     $columns = array();
     $comment = 'AUTO GENERATED THE ' . date('Y-m-d H:i:s');
     $sql = 'CREATE TABLE `' . $this->entity->getTableName() . '` (';
     foreach ($this->entity->getColumnsAttributes() as $columnName => $columnAttributes) {
         $columns[] = $this->createColumnDefinition($columnName, $columnAttributes);
     }
     $sql .= implode(', ', $columns);
     $sql .= $this->createTableConstraints() . PHP_EOL;
     $sql .= ') ENGINE = ' . $this->entity->getEngine();
     if ($this->entity->getCharset() !== '') {
         $sql .= ', CHARACTER SET = ' . $this->entity->getCharset();
     }
     if ($this->entity->getCollation() !== '') {
         $sql .= ', COLLATE = ' . $this->entity->getCollation();
     }
     if ($this->entity->getComment() !== '') {
         $comment .= ' | ' . $this->entity->getComment();
     }
     $sql .= ', COMMENT = \'' . $comment . '\'';
     return DB::exec($sql . ';') !== false;
 }