本文整理汇总了PHP中Database::commit方法的典型用法代码示例。如果您正苦于以下问题:PHP Database::commit方法的具体用法?PHP Database::commit怎么用?PHP Database::commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Database
的用法示例。
在下文中一共展示了Database::commit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update
/**
* Goes through the update files, and updates them.
*/
public function update()
{
try {
$this->versionDao->find(array('number' => 1));
// Throws exception if database not setup.
} catch (DatabaseQueryException $e) {
if ($this->initializeIfNecessary) {
$this->executeUpdate(new DatabaseUpdate($this->initUpdateFilename, 0, 'sql'));
} else {
throw new DatabaseNotInitializedException();
}
}
$this->db->startTransaction();
$updates = $this->getAllUpdates();
foreach ($updates as $update) {
try {
$this->executeUpdate($update);
} catch (Exception $e) {
$this->db->rollback();
throw $e;
}
}
if (count($this->executedUpdates) > 0) {
$this->db->commit();
}
}
示例2: mm_update
public static function mm_update()
{
// Get the RSS feed from Morning Mail
$xml = simplexml_load_file('http://morningmail.rpi.edu/rss');
// Begin the transaction
Database::beginTransaction();
$count = 0;
foreach ($xml->channel->item as $item) {
// Check for duplicates (no DB-agnostic way
// to ignore duplicate errors)
if (self::find($item->link)) {
continue;
}
// Parse data and construct Article objects,
// save them to the DB
$date = date_create($item->pubDate);
$a = new Article($item->title, strip_tags($item->description), $date->format('Y-m-d H:i:s'), $item->link);
// Increment row count
$count++;
if (!$a->save()) {
Database::rollBack();
return false;
}
}
// Commit transaction
Database::commit();
return $count;
}
示例3: do_add
protected function do_add($data)
{
if (!isset($data['set']) || !is_array($data['set'])) {
return array('success' => false);
}
if (!empty($data['start'])) {
$utc = $data['utc'] + 240;
$start = date('Y-m-d G:i:s', strtotime($data['start']) + $utc * 60);
} else {
$start = '';
}
$sets = array();
foreach ($data['set'] as $set) {
if (preg_match('/[^-\\d\\.a-z]/ui', $set)) {
continue;
}
$set = Database::get_full_row('set', 'id = ?', $set);
if (empty($set)) {
continue;
}
$sets[] = $set;
if (!$set['grabbed']) {
Grabber::get_set($set['id']);
}
}
Database::begin();
Database::insert('game', array('id_user' => $this->user, 'pick_time' => isset($data['pick_time']) ? $data['pick_time'] : 0, 'pause_time' => isset($data['pause_time']) ? $data['pause_time'] : 0, 'type' => isset($data['type']) ? $data['type'] : 1, 'start' => $start));
$id_game = Database::last_id();
$order = 0;
foreach ($sets as $set) {
Database::insert('game_set', array('id_game' => $id_game, 'order' => ++$order, 'id_set' => $set['id']));
}
Database::commit();
return array('success' => true);
}
示例4: insert_comment
public function insert_comment($sid, $msg, $parent, $author_name, $author_email)
{
// Connect to database
try {
$handler = new Database();
// Insert comment to database
if ($parent !== 'NULL') {
$handler->beginTransaction();
// If comment has a parent begin transaction
}
$res = $handler->prepare('INSERT INTO `comment`(`sid`, `author_name`, `author_email`, `message`, `parent`) VALUES (:sid, :author_name, :author_email, :message, :parent)');
$res->execute(array(':sid' => $sid, ':author_name' => $author_name, ':author_email' => $author_email, ':message' => $msg, ':parent' => $parent));
if ($res->rowCount() !== 1) {
return false;
}
// Get cid of last comment
$cid = $handler->lastInsertId();
if ($parent !== 'NULL') {
$res = $handler->prepare('UPDATE `comment` SET `children` = 1 WHERE `cid` = :parent');
$res->execute(array(':parent' => $parent));
$handler->commit();
// Commit only if both queries succeed
}
} catch (PDOException $e) {
if ($parent !== 'NULL') {
$handler->rollback();
}
return false;
}
return $cid;
}
示例5: delete_unused_urls
public function delete_unused_urls()
{
Database::begin();
try {
Database::sql('DELETE FROM post_link WHERE
post_id NOT IN (SELECT id FROM post)');
Database::sql('DELETE FROM post_update_link WHERE
update_id NOT IN (SELECT id FROM post_update)');
Database::sql('DELETE FROM post_link_url WHERE
link_id NOT IN (SELECT id FROM post_link)');
Database::sql('DELETE FROM post_update_link_url WHERE
link_id NOT IN (SELECT id FROM post_update_link)');
Database::sql('DELETE FROM post_url WHERE
id NOT IN (SELECT url_id FROM post_link_url) AND
id NOT IN (SELECT url_id FROM post_update_link_url)');
$count = Database::count_affected();
if ($count > self::MAX_LINK_DELETIONS) {
Database::rollback();
throw new Error_Cron('Too many post urls pending for deletion');
}
Database::commit();
} catch (PDOException $e) {
Database::rollback();
throw new Error_Cron('Error with database, while deleting post urls');
}
}
示例6: stepApplySourceFile
/**
* Apply a SQL source file to the database as part of running an installation step.
*
* @param string $sourceFileMethod
* @param string $stepName
* @param bool $archiveTableMustNotExist
* @return Status
*/
private function stepApplySourceFile($sourceFileMethod, $stepName, $archiveTableMustNotExist = false)
{
$status = $this->getConnection();
if (!$status->isOK()) {
return $status;
}
$this->db->selectDB($this->getVar('wgDBname'));
if ($archiveTableMustNotExist && $this->db->tableExists('archive', __METHOD__)) {
$status->warning("config-{$stepName}-tables-exist");
$this->enableLB();
return $status;
}
$this->db->setFlag(DBO_DDLMODE);
// For Oracle's handling of schema files
$this->db->begin(__METHOD__);
$error = $this->db->sourceFile(call_user_func([$this, $sourceFileMethod], $this->db));
if ($error !== true) {
$this->db->reportQueryError($error, 0, '', __METHOD__);
$this->db->rollback(__METHOD__);
$status->fatal("config-{$stepName}-tables-failed", $error);
} else {
$this->db->commit(__METHOD__);
}
// Resume normal operations
if ($status->isOK()) {
$this->enableLB();
}
return $status;
}
示例7: execute
public function execute()
{
$dbh =& Database::connection();
$this->result = $dbh->prepare($this->__toString());
$this->result->execute();
Database::commit();
$dbh = null;
}
示例8: processUpdates
/**
* Package metadata updates.
*
* @param Database $db
* @param array $updates
* @return bool
* @throws TypeError
*/
function processUpdates(Database $db, array $updates = []) : bool
{
$db->beginTransaction();
foreach ($updates as $update) {
$db->update('airship_package_cache', ['skyport_metadata' => \json_encode($update['metadata'])], ['packagetype' => $update['package']['type'], 'supplier' => $update['package']['supplier'], 'name' => $update['package']['name']]);
}
return $db->commit();
}
示例9: shutdown
function shutdown()
{
if (Database::hasBeenUsed()) {
Database::commit();
}
// Jobs must not write to database!
$queue = JobQueue::getInstance();
$jobs = $queue->executeJobs();
gfDebug("Request ended.\n");
}
示例10: evolve
public function evolve($buildingId)
{
//check building
$result = $this->db->prepare("SELECT id FROM buildings WHERE id = ?");
$result->execute([$buildingId]);
if ($result->rowCount() < 0) {
throw new \Exception("Building with such id does not exists");
}
//get resources
$resources = $this->db->prepare("\n SELECT\n (SELECT gold FROM building_levels WHERE building_id = b.id AND level = (SELECT level FROM building_levels WHERE id = ub.level_id) + 1) AS gold,\n (SELECT food FROM building_levels WHERE building_id = b.id AND level = (SELECT level FROM building_levels WHERE id = ub.level_id) + 1) AS food\n FROM buildings as b\n INNER JOIN user_buildings AS ub ON ub.building_id = b.id\n INNER JOIN building_levels AS bl ON bl.id = ub.level_id\n WHERE ub.user_id = ? AND b.id = ?;\n ");
$resources->execute([$this->user->getId(), $buildingId]);
$resourcesData = $resources->fetch();
if ($this->getUser()->getFood() < $resourcesData['food'] || $this->getUser()->getGold() < $resourcesData['gold']) {
throw new \Exception("No resources");
}
//max level
$maxLevel = $this->db->prepare("\n SELECT\n MAX(bl.level) AS level\n FROM building_levels bl\n WHERE bl.building_id = ?\n ");
$maxLevel->execute([$buildingId]);
$maxLevelData = $maxLevel->fetch();
//current level
$currentLevel = $this->db->prepare("\n SELECT\n bl.level\n FROM user_buildings ub\n JOIN building_levels bl ON bl.id = ub.level_id\n WHERE ub.building_id = ?\n ");
$currentLevel->execute([$buildingId]);
$currentLevelData = $currentLevel->fetch();
if ($maxLevelData['level'] < $currentLevelData['level']) {
throw new \Exception("Max level reached");
}
$this->db->beginTransaction();
$resourceUpdate = $this->db->prepare("\n UPDATE\n users\n SET\n gold = gold - ?, food = food - ?\n WHERE id = ?\n ");
$resourceUpdate->execute([$resourcesData['gold'], $resourcesData['food'], $this->getUser()->getId()]);
if ($resourceUpdate->rowCount() > 0) {
$levelUpdate = $this->db->prepare("\n UPDATE\n user_buildings ub\n SET\n ub.level_id = (SELECT bl.id FROM building_levels bl WHERE level = ? AND bl.building_id = ub.building_id)\n WHERE ub.user_id = ? AND ub.building_id = ?\n ");
$levelUpdate->execute([$currentLevelData['level'] + 1, $this->getUser()->getId(), $buildingId]);
if ($levelUpdate->rowCount() > 0) {
$this->db->commit();
return true;
} else {
$this->db->rollBack();
throw new \Exception("Level up error");
}
} else {
throw new \Exception("Resource update error");
}
}
示例11: setUp
public function setUp()
{
parent::setUp();
LudoDBRegistry::set('FILE_UPLOAD_PATH', '/tmp/');
$mv = new MetadataValue();
$mv->drop()->yesImSure();
$m = new Move();
$m->drop()->yesImSure();
$g = new Game();
$g->drop()->yesImSure();
$g->createTable();
$m->createTable();
$mv->createTable();
$db = new Database(1);
if (!$db->getId()) {
$db->setTitle('My database');
$db->commit();
}
}
示例12: start
public function start($users)
{
// Уже запущен
if ($this->get('state') != 0) {
return false;
}
$users = array_filter(explode(',', $users));
$users[] = $this->get('id_user');
$users = array_unique($users);
shuffle($users);
Database::begin();
try {
$this->create_data($users);
} catch (Error $e) {
Database::rollback();
return false;
}
Database::commit();
return true;
}
示例13: save
public static function save()
{
// Clear out current clusters, TRUNCATE is implicitly
// commited so it ruins the transaction, thats why its
// out here
Database::query("TRUNCATE centers;");
// Initiate a large transaction to the DB
Database::beginTransaction();
// Save every cluster to the DB
foreach (self::$clusters as $cluster) {
if (!$cluster->save()) {
// Undo all changes to the DB
Database::rollBack();
return false;
}
}
// Commit the entire transaction
Database::commit();
return true;
}
示例14: main
public function main()
{
Database::begin();
try {
$data = $this->reader->get_data();
foreach ($data as $key => $value) {
if (method_exists($this, $key)) {
$this->{$key}($data);
}
}
if (!empty($data['edit']) && !array_key_exists($data['edit'], $data) && method_exists($this, $data['edit'])) {
$function = $data['edit'];
$this->{$function}($data);
}
$this->save_changes();
Database::commit();
} catch (PDOException $e) {
Database::rollback();
}
}
示例15: Database
//.........这里部分代码省略.........
$_SESSION['g_user'] = 'phpcompta';
$_SESSION['g_pass'] = 'phpcompta';
$id = isset($_REQUEST['p_jrn']) ? $_REQUEST['p_jrn'] : -1;
$a = new Acc_Ledger($cn, $id);
$a->with_concerned = true;
// Vide
echo '<FORM method="post">';
echo $a->select_ledger()->input();
echo HtmlInput::submit('go', 'Test it');
echo '</form>';
if (isset($_POST['go'])) {
echo "Ok ";
echo '<form method="post">';
echo $a->show_form();
echo HtmlInput::submit('post_id', 'Try me');
echo '</form>';
// Show the predef operation
// Don't forget the p_jrn
echo '<form>';
echo dossier::hidden();
echo '<input type="hidden" value="' . $id . '" name="p_jrn">';
$op = new Pre_operation($cn);
$op->p_jrn = $id;
$op->od_direct = 't';
if ($op->count() != 0) {
echo HtmlInput::submit('use_opd', 'Utilisez une opération prédéfinie', "", "smallbutton");
echo $op->show_button();
}
echo '</form>';
exit('test_me');
}
if (isset($_POST['post_id'])) {
echo '<form method="post">';
echo $a->show_form($_POST, 1);
echo HtmlInput::button('add', 'Ajout d\'une ligne', 'onClick="quick_writing_add_row()"');
echo HtmlInput::submit('save_it', _("Sauver"));
echo '</form>';
exit('test_me');
}
if (isset($_POST['save_it'])) {
print 'saving';
$array = $_POST;
$array['save_opd'] = 1;
try {
$a->save($array);
} catch (Exception $e) {
alert($e->getMessage());
echo '<form method="post">';
echo $a->show_form($_POST);
echo HtmlInput::submit('post_id', 'Try me');
echo '</form>';
}
return;
}
// The GET at the end because automatically repost when you don't
// specify the url in the METHOD field
if (isset($_GET['use_opd'])) {
$op = new Pre_op_advanced($cn);
$op->set_od_id($_REQUEST['pre_def']);
//$op->p_jrn=$id;
$p_post = $op->compute_array();
echo '<FORM method="post">';
echo $a->show_form($p_post);
echo HtmlInput::submit('post_id', 'Use predefined operation');
echo '</form>';
return;
}
}
// if case = ''
///////////////////////////////////////////////////////////////////////////
// search
if ($pCase == 'search') {
html_page_start();
$cn = new Database(dossier::id());
$ledger = new Acc_Ledger($cn, 0);
$_SESSION['g_user'] = 'phpcompta';
$_SESSION['g_pass'] = 'phpcompta';
echo $ledger->search_form('ALL');
}
///////////////////////////////////////////////////////////////////////////
// reverse
// Give yourself the var and check in your tables
///////////////////////////////////////////////////////////////////////////
if ($pCase == 'reverse') {
$cn = new Database(dossier::id());
$jr_internal = 'OD-01-272';
try {
$cn->start();
$jrn_def_id = $cn->get_value('select jr_def_id from jrn where jr_internal=$1', array($jr_internal));
$ledger = new Acc_Ledger($cn, $jrn_def_id);
$ledger->jr_id = $cn->get_value('select jr_id from jrn where jr_internal=$1', array($jr_internal));
echo "Ouvrez le fichier " . __FILE__ . " à la ligne " . __LINE__ . " pour changer jr_internal et vérifier le résultat de l'extourne";
$ledger->reverse('01.07.2010');
} catch (Exception $e) {
$cn->rollback();
var_dump($e);
}
$cn->commit();
}
}