Example #1
0
function addQuestionTODB($catcracker_newquestion_passage, $catcracker_newquestion_question, $catcracker_newquestion_optiona, $catcracker_newquestion_optionb, $catcracker_newquestion_optionc, $catcracker_newquestion_optiond, $catcracker_newquestion_rightanswer, $catcracker_newquestion_difficultylevel, $catcracker_newquestion_challengequestion, $catcracker_newquestion_tags)
{
    $conn = $GLOBALS['conn'];
    $sql = "INSERT INTO `catcracker_questions` (`id`, `difficulty`, `owner`, `link`, `timestamp`, `tags`, `rating`, `challenge`)";
    $sql .= " VALUES (NULL, ?, ?, ?, ?, ?);";
    $q = $conn->prepare($sql);
    $e = time();
    $criteria = array($catcracker_newquestion_difficultylevel, $_SESSION['userid'], $catcracker_newquestion_passage, $e, $catcracker_newquestion_tags, "5", $catcracker_newquestion_challengequestion);
    $q->execute($criteria);
    if ($q == null || hasDBError($q->errorInfo())) {
        throw new Exception("newquestion.db.adderror");
    }
    $questionid = $conn->lastInsertId();
    for ($i = 0; $i < sizeof($catcracker_newquestion_question); $i++) {
        $sql = "INSERT INTO `catcracker_question` (`questionid`, `question`, `optiona`, `optionb`, `optionc`, `optiond`, `answer`)";
        $sql .= "VALUES (?,?,?,?,?,?,?);";
        $q = $conn->prepare($sql);
        $criteria = array($questionid, $catcracker_newquestion_question[$i], $catcracker_newquestion_optiona[$i], $catcracker_newquestion_optionb[$i], $catcracker_newquestion_optionc[$i], $catcracker_newquestion_optiond[$i], $catcracker_newquestion_rightanswer[$i]);
        $q->execute($criteria);
        if ($q == null || hasDBError($q->errorInfo())) {
            throw new Exception("newquestion.db.adderror");
        }
    }
    return $questionid;
}
Example #2
0
function queryDB($str)
{
    $conn = $GLOBALS['conn'];
    $res = $conn->prepare($str);
    $res->execute();
    if ($res == null || hasDBError($res->errorInfo())) {
        throw new Exception("install.sql.error");
    }
}