Beispiel #1
0
| 인천   |
| 전남   |
| 전북   |
| 제주   |
| 충남   |
| 충북   |
*/
R::setup( 'mysql:host=localhost;dbname=smartqna',
					'root', 'denters0318' ); 

$region= R::dispense('region');

$region->lv0='string';
$region->lv1='string';

setUnique($region, array('lv0', 'lv1'));
safeStore($region);

function safeStore($obj)
{
	try {
		$id	= R::store($obj);
		echo "saved id [$id]";
	} catch (RedBeanPHP\RedException\SQL $e) {
		echo "failed: $e<br><br>";
	}
}

function setUnique($bean, $arr)
{
	$bean->setMeta("buildcommand.unique" , array($arr));
Beispiel #2
0
    $book->name = 'EBS수2미분과적분';
    $book->publisher = 'EBS';
    //setUnique($book, array('name'));
    safeStore($book);
    //mentor
    $mentor = R::dispense('mentor');
    $mentor->name = '곽동녘';
    $mentor->dept = '연세대';
    $mentor->imgurl = 'http://venusproject.co.kr/smartqna/data/img/mentor/001.jpg';
    $mentor->motto = 'be the best';
    $mentor->msg = 'fighting!';
    safeStore($mentor);
    $map = R::dispense('mentor2book');
    $map->mentorid = 1;
    $map->bookid = 4;
    setUnique($map, array('mentorId', 'bookId'));
    safeStore($map);
});
$app->post('/login', function () use($app) {
    $body = $app->request->getBody();
    $json = json_decode($body);
    $uid = $json->{'uid'};
    $pass = $json->{'pass'};
    $user = R::findOne('user', "uid = '{$uid}' AND pass = PASSWORD('{$pass}')");
    if (isset($user)) {
        success(R::exportAll($user));
    } else {
        fail("id/pass mismatch, body:{$body}");
    }
});
$app->post('/signup', function () use($app) {