Exemplo n.º 1
0
function _themeIdea_AddWithLimit($idea, $event_id, $user_id, $limit)
{
    global $db;
    _db_Connect();
    // Only because we're doing native DB ops, call connect //
    $db->begin_transaction();
    $count = 0;
    try {
        $count = themeIdea_Count($event_id, $user_id, " FOR UPDATE;");
        if ($count === false) {
            throw new Exception();
        }
        if ($count >= $limit) {
            throw new Exception();
        }
        $result = db_QueryInsert("INSERT INTO " . SH_TABLE_PREFIX . SH_TABLE_THEME_IDEA . " (\n\t\t\t\ttheme, node, user, timestamp\n\t\t\t)\n\t\t\tVALUES ( \n\t\t\t\t?, ?, ?, NOW()\n\t\t\t)", $idea, $event_id, $user_id);
        if (empty($result)) {
            throw new Exception();
        }
        $count = themeIdea_Count($event_id, $user_id);
        if ($count === false) {
            throw new Exception();
        }
        if ($count > $limit) {
            throw new Exception();
        }
        // We're good! Commit! We're finished //
        $db->commit();
        return ["id" => $result, "count" => $count];
    } catch (Exception $ex) {
        // Bad! Do a rollback! //
        $db->rollback();
        return ["id" => 0, "count" => $count];
    }
}
Exemplo n.º 2
0
function _db_Query($query, $args)
{
    _db_Connect();
    $st = _db_Prepare($query);
    if ($st && _db_BindExecute($st, $args)) {
        return $st;
    }
    _db_DBError();
    return false;
}