本文整理汇总了PHP中sql_commit函数的典型用法代码示例。如果您正苦于以下问题:PHP sql_commit函数的具体用法?PHP sql_commit怎么用?PHP sql_commit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sql_commit函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sql_transaction
function sql_transaction($lines = array(), $return_last_insert_id = TRUE)
{
//sql_rollback();
sql_begin();
if (!is_array($lines)) {
$lines = array($lines);
}
foreach ($lines as $line) {
$result = sql_query_dbg($line, true);
}
if (count($lines)) {
if ($return_last_insert_id) {
//we must get the insert id before commiting
$ret = sql_insert_id();
}
}
sql_commit();
if (count($lines) && !$return_last_insert_id) {
$ret = sql_affected_rows($result);
}
return $ret;
}
示例2: check_permission
try {
check_permission(PERM_ADDER);
if (!isset($_POST['sid']) || !isset($_POST['book_id'])) {
throw new UnexpectedValueException();
}
$sid = $_POST['sid'];
$book_id = $_POST['book_id'];
sql_begin();
//creating book if necessary
if ($book_id == -1) {
//find the parent id
$res = sql_pe("SELECT book_id, url FROM sources WHERE source_id = (SELECT parent_id FROM sources WHERE source_id=? LIMIT 1) LIMIT 1", array($sid));
if (!isset($_POST['book_name']) || !$res[0]['book_id']) {
throw new UnexpectedValueException();
}
$book_id = books_add($_POST['book_name'], $res[0]['book_id']);
$res = sql_pe("SELECT url FROM sources WHERE source_id=? LIMIT 1", array($sid));
books_add_tag($book_id, 'url:' . $res[0]['url']);
download_url($res[0]['url']);
}
//bind
sql_pe("UPDATE sources SET book_id=? WHERE source_id=? LIMIT 1", array($book_id, $sid));
sql_commit();
$res = sql_pe("SELECT book_name FROM books WHERE book_id=? LIMIT 1", array($book_id));
$result['title'] = htmlspecialchars($res[0]['book_name']);
$result['book_id'] = $book_id;
} catch (Exception $e) {
$result['error'] = 1;
}
log_timing(true);
die(json_encode($result));
示例3: get_user_options
public function get_user_options($user_id)
{
if (!$user_id) {
throw new UnexpectedValueException();
}
$out = array();
$res = sql_query("SELECT option_id id, option_value value FROM user_options_values WHERE user_id={$user_id}");
while ($r = sql_fetch_array($res)) {
$out[$r['id']] = $r['value'];
}
//autovivify absent options
sql_begin();
$ins = sql_prepare("INSERT INTO user_options_values VALUES(?, ?, ?)");
foreach ($this->options as $opt) {
if (!in_array($opt->id, array_keys($out))) {
$out[$opt->id] = $opt->default_value;
sql_execute($ins, array($user_id, $opt->id, $opt->default_value));
}
}
sql_commit();
return $out;
}
示例4: save_user_team
function save_user_team($team_id, $new_team_name = false)
{
check_logged();
sql_begin();
// create new team if necessary
if ($new_team_name) {
sql_pe("INSERT INTO user_teams VALUES(NULL, ?, ?)", array(trim($new_team_name), $_SESSION['user_id']));
$team_id = sql_insert_id();
}
sql_pe("UPDATE users SET user_team=? WHERE user_id=? LIMIT 1", array($team_id, $_SESSION['user_id']));
sql_commit();
return $team_id;
}
示例5: save_moderated_answer
function save_moderated_answer($id, $answer, $manual, $field_name = 'answer')
{
check_permission(PERM_MORPH_MODER);
$user_id = $_SESSION['user_id'];
if (!$id || !$user_id || $answer < 0) {
throw new UnexpectedValueException();
}
$r = sql_fetch_array(sql_query("SELECT pool_id FROM morph_annot_samples WHERE sample_id = {$id} LIMIT 1"));
$pool_id = $r['pool_id'];
sql_begin();
if (!check_moderator_right($user_id, $pool_id, true)) {
throw new Exception("Вы не модератор этого пула");
}
sql_query("UPDATE morph_annot_moderated_samples SET user_id={$user_id}, `{$field_name}`={$answer}, `manual`={$manual} WHERE sample_id={$id} LIMIT 1");
sql_commit();
if ($field_name != 'answer') {
return 1;
}
//check whether it was the last sample to be moderated
$res = sql_query("\n SELECT sample_id\n FROM morph_annot_moderated_samples\n LEFT JOIN morph_annot_samples USING (sample_id)\n WHERE pool_id={$pool_id}\n AND answer = 0\n LIMIT 1\n ");
if (sql_num_rows($res) == 0) {
return 2;
}
return 1;
}
示例6: delete_fact
function delete_fact($fact_id)
{
sql_begin();
sql_pe("DELETE FROM fact_field_values WHERE fact_id = ?", array($fact_id));
sql_pe("DELETE FROM facts WHERE fact_id = ?", array($fact_id));
sql_commit();
}
示例7: split_token
function split_token($token_id, $num)
{
//$num is the number of characters (in the beginning) that should become a separate token
check_permission(PERM_ADDER);
if (is_token_covered_by_ne_markup($token_id)) {
throw new Exception("Cannot split token under NE markup");
}
if (!$token_id || !$num) {
throw new UnexpectedValueException();
}
$res = sql_pe("SELECT tf_text, sent_id, pos FROM tokens WHERE tf_id=? LIMIT 1", array($token_id));
if (sizeof($res) == 0) {
throw new Exception();
}
$r = $res[0];
$text1 = trim(mb_substr($r['tf_text'], 0, $num));
$text2 = trim(mb_substr($r['tf_text'], $num));
if (!$text1 || !$text2) {
throw new Exception();
}
sql_begin();
//create revset
$revset_id = create_revset("Token {$token_id} (<" . $r['tf_text'] . ">) split to <{$text1}> and <{$text2}>");
$token_for_form2tf = str_replace('ё', 'е', mb_strtolower($text1));
//update other tokens in the sentence
sql_query("UPDATE tokens SET pos=pos+1 WHERE sent_id = " . $r['sent_id'] . " AND pos > " . $r['pos']);
//create new token and parse
sql_pe("INSERT INTO tokens VALUES(NULL, ?, ?, ?)", array($r['sent_id'], $r['pos'] + 1, $text2));
$parse1 = new MorphParseSet(false, $text1);
$parse2 = new MorphParseSet(false, $text2);
create_tf_revision($revset_id, sql_insert_id(), $parse2->to_xml());
//update old token and parse
sql_pe("DELETE FROM form2tf WHERE tf_id=?", array($token_id));
sql_pe("UPDATE tokens SET tf_text=? WHERE tf_id=? LIMIT 1", array($text1, $token_id));
sql_pe("INSERT INTO form2tf VALUES(?, ?)", array($token_for_form2tf, $token_id));
create_tf_revision($revset_id, $token_id, $parse1->to_xml());
//dropping sentence status
$res = sql_pe("SELECT sent_id FROM tokens WHERE tf_id=? LIMIT 1", array($token_id));
$sent_id = $res[0]['sent_id'];
sql_query("UPDATE sentences SET check_status='0' WHERE sent_id={$sent_id} LIMIT 1");
sql_query("DELETE FROM sentence_check WHERE sent_id={$sent_id}");
sql_commit();
$res = sql_query("SELECT book_id FROM paragraphs WHERE par_id = (SELECT par_id FROM sentences WHERE sent_id={$sent_id} LIMIT 1)");
$r = sql_fetch_array($res);
return array($r['book_id'], $sent_id);
}
示例8: create_tf_revision
function create_tf_revision($revset_id, $token_id, $rev_xml)
{
$res = sql_pe("SELECT rev_text FROM tf_revisions WHERE tf_id=? ORDER BY rev_id DESC LIMIT 1", array($token_id));
if (sizeof($res) > 0 && $res[0]['rev_text'] === $rev_xml) {
// revisions are identical, do nothing
return true;
}
sql_begin();
sql_pe("UPDATE tf_revisions SET is_last=0 WHERE tf_id=?", array($token_id));
sql_pe("INSERT INTO `tf_revisions` VALUES(NULL, ?, ?, ?, 1)", array($revset_id, $token_id, $rev_xml));
sql_commit();
}
示例9: add_anaphora
function add_anaphora($anaphor_id, $antecedent_id)
{
check_permission(PERM_SYNTAX);
// check that anaphor exists and has Anph grammeme
$res = sql_pe("SELECT rev_text FROM tf_revisions WHERE tf_id=? AND is_last=1 LIMIT 1", array($anaphor_id));
if (sizeof($res) == 0) {
throw new Exception();
}
$r = $res[0];
if (strpos($r['rev_text'], '<g v="Anph"/>') === false) {
throw new Exception();
}
// check that antecedent exists
$res = sql_pe("SELECT * FROM anaphora_syntax_groups WHERE group_id=? LIMIT 1", array($antecedent_id));
if (sizeof($res) == 0) {
throw new Exception();
}
// TODO check that the group belongs to the moderator
// TODO check that both token and group are within one book
sql_begin();
$revset_id = create_revset();
sql_pe("INSERT INTO anaphora VALUES (NULL, ?, ?, ?, ?)", array($anaphor_id, $antecedent_id, $revset_id, $_SESSION['user_id']));
$id = sql_insert_id();
sql_commit();
return $id;
}
示例10: revert_dict
function revert_dict($rev_id)
{
if (!$rev_id) {
throw new UnexpectedValueException();
}
check_permission(PERM_DICT);
$res = sql_pe("SELECT lemma_id, rev_text FROM dict_revisions WHERE rev_id=? LIMIT 1", array($rev_id));
$lemma_id = $res[0]['lemma_id'];
$old_rev = sql_pe("SELECT rev_text FROM dict_revisions WHERE lemma_id=? and is_last=1 LIMIT 1", array($lemma_id));
sql_begin();
$new_set_id = create_revset("Отмена правки, возврат к версии d{$rev_id}");
$new_rev_id = new_dict_rev($lemma_id, $res[0]['rev_text'], $new_set_id);
// updated forms
$pdr = parse_dict_rev($old_rev[0]['rev_text']);
enqueue_updated_forms(calculate_updated_forms($pdr, parse_dict_rev($res[0]['rev_text'])), $new_rev_id);
sql_commit();
}
示例11: _save_found_tokens
private function _save_found_tokens($token_sets)
{
sql_begin();
foreach ($token_sets as $tset) {
if (!$tset instanceof FoundTokens) {
throw new Exception();
}
sql_pe("INSERT INTO mw_main (status, applied, mw_type) VALUES (?, ?, ?)", array(MultiWordTask::NOT_READY, MultiWordTask::NOT_APPLIED, $tset->type));
$mw_id = sql_insert_id();
foreach ($tset as $tf_id) {
sql_pe("INSERT INTO mw_tokens (mw_id, tf_id) VALUES (?, ?)", array($mw_id, $tf_id));
}
}
sql_commit();
}
示例12: finish_book_moderation
function finish_book_moderation($book_id, $tagset_id)
{
check_permission(PERM_NE_MODER);
// create absent annotations
$res = sql_pe("\n SELECT par_id FROM paragraphs\n LEFT JOIN ne_paragraphs USING (par_id)\n WHERE book_id = ?\n AND tagset_id = ?\n GROUP BY par_id\n HAVING COUNT(annot_id) = 0\n ", array($book_id, $tagset_id));
sql_begin();
foreach ($res as $r) {
start_ne_annotation($r['par_id'], $tagset_id, true);
}
set_ne_book_status($book_id, $tagset_id, NE_STATUS_FINISHED);
sql_commit();
}
示例13: calculate_gram_restrictions
function calculate_gram_restrictions()
{
check_permission(PERM_DICT);
sql_begin();
sql_query("DELETE FROM gram_restrictions WHERE `auto`=1");
$restr = array();
$res = sql_query("SELECT r.if_id, r.then_id, r.obj_type, r.restr_type, g1.gram_id gram1, g2.gram_id gram2\n FROM gram_restrictions r\n LEFT JOIN gram g1 ON (r.then_id = g1.parent_id)\n LEFT JOIN gram g2 ON (g1.gram_id = g2.parent_id)\n WHERE r.restr_type>0");
while ($r = sql_fetch_array($res)) {
$restr[] = $r['if_id'] . '#' . $r['then_id'] . '#' . $r['obj_type'] . '#' . $r['restr_type'];
if ($r['gram1']) {
$restr[] = $r['if_id'] . '#' . $r['gram1'] . '#' . $r['obj_type'] . '#' . $r['restr_type'];
}
if ($r['gram2']) {
$restr[] = $r['if_id'] . '#' . $r['gram2'] . '#' . $r['obj_type'] . '#' . $r['restr_type'];
}
}
$restr = array_unique($restr);
foreach ($restr as $quad) {
list($if, $then, $type, $w0) = explode('#', $quad);
$w = $w0 == 1 ? 0 : 2;
if (sql_num_rows(sql_query("SELECT restr_id FROM gram_restrictions WHERE if_id={$if} AND then_id={$then} AND obj_type={$type} AND restr_type={$w}")) == 0) {
sql_query("INSERT INTO gram_restrictions VALUES(NULL, '{$if}', '{$then}', '{$w}', '{$type}', '1')");
}
}
sql_commit();
}
示例14: addtext_add
function addtext_add($text, $sentences, $book_id, $par_num)
{
check_permission(PERM_ADDER);
if (!$text || !$book_id || !$par_num) {
throw new UnexpectedValueException();
}
if (sizeof(sql_pe("SELECT book_id FROM books WHERE parent_id=?", array($book_id))) > 0) {
throw new UnexpectedValueException("Can't add paragraphs to a text having subtexts");
}
sql_begin();
$revset_id = create_revset();
$sent_count = 0;
$pars = split2paragraphs($text);
// move the following paragraphs
sql_query("UPDATE paragraphs SET pos=pos+" . sizeof($pars) . " WHERE book_id = {$book_id} AND pos >= {$par_num}");
$par_ins = sql_prepare("INSERT INTO `paragraphs` VALUES(NULL, ?, ?)");
$sent_ins = sql_prepare("INSERT INTO `sentences` VALUES(NULL, ?, ?, ?, 0)");
$token_ins = sql_prepare("INSERT INTO `tokens` VALUES(NULL, ?, ?, ?)");
foreach ($pars as $par) {
//adding a paragraph
sql_execute($par_ins, array($book_id, $par_num++));
$par_id = sql_insert_id();
$sent_num = 1;
$sents = split2sentences($par);
foreach ($sents as $sent) {
if (!preg_match('/\\S/', $sent)) {
continue;
}
//adding a sentence
sql_execute($sent_ins, array($par_id, $sent_num++, trim($sent)));
$sent_id = sql_insert_id();
sql_query("INSERT INTO sentence_authors VALUES({$sent_id}, " . $_SESSION['user_id'] . ", " . time() . ")");
$token_num = 1;
$tokens = explode('^^', $sentences[$sent_count++]);
foreach ($tokens as $token) {
if (trim($token) === '') {
continue;
}
//adding a textform
sql_execute($token_ins, array($sent_id, $token_num++, trim($token)));
$tf_id = sql_insert_id();
//adding a revision
$parse = new MorphParseSet(false, trim($token));
create_tf_revision($revset_id, $tf_id, $parse->to_xml());
}
}
}
sql_commit();
}
示例15: delete_mention
function delete_mention($mention_id)
{
sql_begin();
sql_pe("DELETE FROM ne_entities_mentions WHERE mention_id = ?", array($mention_id));
sql_pe("DELETE FROM ne_mentions WHERE mention_id = ?", array($mention_id));
sql_commit();
}