Exemplo n.º 1
0
<?php

require_once 'autoloader.php';
use Orm\Orm;
use Model\Users;
$initialisation = Orm::init('localhost', 'testorm', 'root', 'root');
$orm = new Orm();
// INSERT IN BDD
//$user = new Users();
//$user->setName('Raphael');
//$user->setMail('*****@*****.**');
//$user->setPassword(sha1('qwerty123'));
//$orm->persist($user);
//<--------------------------------------    -------------------------------------->
// GET
//$orm = new Orm();
//$users = new Users();
//$tabUsers = $orm->getAll($users);
//var_dump($tabUsers);
//
//foreach($tabUsers as $user){
//    echo 'Nom : ' . $user['name'] . '<br>';
//    echo 'Email : ' . $user['mail'] . '<br>';
//    echo 'Password : '******'password'] . '<br>';
//    echo '----<br>';
//}
//<--------------------------------------    -------------------------------------->
// DELETE BY ID
//$orm = new Orm();
//$users = new Users();
//$users->setId('40');
Exemplo n.º 2
0
<?php

require_once 'autoloader.php';
use Orm\Orm;
//localhost testorm root root users users
$dbHost = $argv[1];
$dbName = $argv[2];
$dbUser = $argv[3];
$dbPass = $argv[4];
$tableName = $argv[5];
$className = ucfirst($argv[6]);
// Connexion à la BDD & requête afin de récuperer chaque nom de colonnes
Orm::init($dbHost, $dbName, $dbUser, $dbPass);
$req = Orm::getConnexion()->prepare('SHOW COLUMNS FROM ' . $tableName);
$req->execute();
$fields = $req->fetchAll(PDO::FETCH_COLUMN, 0);
$space = 4;
function do_tabs($space)
{
    $ret = '';
    for ($i = 0; $i < $space; $i++) {
        $ret .= ' ';
    }
    return $ret;
}
$code = "<?php\n\n";
$code .= "namespace Model;\n\n";
$code .= "class {$className}\n{\n";
foreach ($fields as $field) {
    $code .= do_tabs($space) . 'protected $' . $field . ";\n";
}