Esempio n. 1
0
 public function persist()
 {
     $table = $this->getTable();
     $connexion = Orm::getConnexion();
     $columns = $connexion->query("SELECT table_name, column_name, data_type FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '{$table}' AND table_schema = 'orm';")->fetchAll();
     $methods = [];
     foreach ($columns as $column) {
         if ($column['column_name'] == 'id') {
             continue;
         } else {
             $methods[$column['column_name']] = 'get' . ucfirst($column['column_name']);
         }
     }
     if ($this->getId() != null) {
         $query = $this->update($methods, $this);
         $connexion->query($query);
     } else {
         $query = $this->insert($methods, $this);
         $connexion->query($query);
         $result = $connexion->lastInsertId();
         $this->setId($result);
     }
 }
Esempio n. 2
0
    for ($i = 0; $i < $n; $i++) {
        $ret .= "\t";
    }
    return $ret;
}
function jump($n = 0)
{
    $ret = "\n";
    for ($i = 0; $i < $n; $i++) {
        $ret .= "\n";
    }
    return $ret;
}
use Orm\Orm\Orm;
Orm::init();
$connexion = Orm::getConnexion();
$result = $connexion->query("Show columns FROM user")->fetchAll();
$fields = [];
foreach ($result as $field) {
    array_push($fields, $field['Field']);
}
$className = $argv[1];
// Do some magic here
$code = "<?php " . jump(2);
$code .= "namespace Orm\\Entity;" . jump(2);
$code .= "use Orm\\Orm\\QueryManager;" . jump(2);
$code .= "class {$className} extends QueryManager" . jump() . "{" . jump();
foreach ($fields as $field) {
    $code .= do_tabs() . 'protected $' . $field . ";" . jump();
}
$code .= jump();
Esempio n. 3
0
<?php

/**
 * Created by PhpStorm.
 * User: Younes
 * Date: 13/12/2015
 * Time: 17:57
 */
require_once 'vendor/autoload.php';
require_once __DIR__ . '/config.php';
use Orm\Orm\Orm, Orm\Entity\User;
Orm::init();
$user = new User();
$user->setMail('*****@*****.**');
$user->setUsername('younes');
$user->setPassword('younes');
$user->save();
$user->setUsername('LOL');
$user->save();
$nmbUser = User::countItem();
var_dump($nmbUser);
//$user->deleteD();
$nmbUser = User::countItem();
var_dump($nmbUser);