コード例 #1
0
ファイル: include.php プロジェクト: nivertech/VoodOrm
<?php

include dirname(__DIR__) . "/src/Voodoo/Core/VoodOrm.php";
function getPdo()
{
    $PDO = new PDO("mysql:host=localhost;dbname=voodorm_test", "root", "");
    $PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    return $PDO;
}
$SQL = "\n\n-- DROP TABLE IF EXISTS `user`;\nCREATE TABLE IF NOT EXISTS `user` (\n  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,\n  `name` varchar(125) NOT NULL,\n  `created_datetime` datetime NOT NULL,\n  PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;\n\n\n-- DROP TABLE IF EXISTS `friend`;\nCREATE TABLE IF NOT EXISTS `friend` (\n  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,\n  `user_id` int(11) unsigned NOT NULL,\n  `friend_user_id` int(11) unsigned NOT NULL\n  PRIMARY KEY (`id`),\n  KEY `friend_user_id` (`friend_user_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;    \n\n";
getPdo()->exec($SQL);
コード例 #2
0
ファイル: update.php プロジェクト: nivertech/VoodOrm
<?php

include __DIR__ . "/include.php";
use Voodoo\Core;
$DB = new Core\VoodOrm(getPdo());
$users = $DB->user();
// or $DB->table("user");
$userId = 1;
try {
    $user = $users->findOne($userId);
    if ($user) {
        $user->name = "Changed Name";
        // or
        $user->set("name", "Another name");
        // or
        $user->set(array("name" => "Another name changed"));
        $user->update();
        //or $user->save();
    }
} catch (Exception $e) {
    echo "ERROR: " . $e->getMessage();
}