当前位置: 首页>>代码示例>>PHP>>正文


PHP DB::start_transaction方法代码示例

本文整理汇总了PHP中DB::start_transaction方法的典型用法代码示例。如果您正苦于以下问题:PHP DB::start_transaction方法的具体用法?PHP DB::start_transaction怎么用?PHP DB::start_transaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DB的用法示例。


在下文中一共展示了DB::start_transaction方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: post_config

 /**
  * post_config
  * 
  * @access  public
  * @return  Response (json, html)
  */
 public function post_config($name = null)
 {
     $this->api_accept_formats = array('json', 'html');
     $this->controller_common_api(function () use($name) {
         if (!is_null(Input::post('name'))) {
             $name = Input::post('name');
         }
         $value = Input::post('value');
         self::check_name_format_for_update_config($name);
         $this->check_response_format_for_update_config($name);
         $this->response_body['message'] = self::get_success_message($name);
         $this->response_body['errors']['message_default'] = self::get_error_message_default($name);
         $member_id = (int) $this->u->id;
         if (!($member_config = Model_MemberConfig::get_one4member_id_and_name($member_id, $name))) {
             $member_config = Model_MemberConfig::forge();
             $member_config->member_id = $member_id;
             $member_config->name = $name;
         }
         $current_value = isset($member_config->value) ? $member_config->value : null;
         $value = self::validate_posted_value($name, $current_value);
         $member_config->value = $value;
         \DB::start_transaction();
         $member_config->save();
         \DB::commit_transaction();
         $response_body = self::get_response_for_update_config($name, array('id' => $member_id, $name => $value));
         $this->response_body = $this->format == 'html' ? $response_body : array('html' => $response_body, 'message' => sprintf('%sを%sしました。', term('site.display', 'site.setting'), term('form.update')));
     });
 }
开发者ID:uzura8,项目名称:flockbird,代码行数:34,代码来源:api.php

示例2: action_regist

 public function action_regist()
 {
     try {
         DB::start_transaction();
         //$this->checkCsrf();
         // バリデーションチェック
         $val = Validation::forge();
         $val->add("hospital_id", "病院ID")->add_rule("required");
         $val->add("nickname", "清潔感")->add_rule("required");
         $val->add("message", "内容")->add_rule("required");
         $param = $this->validate($val);
         $hospitalId = $param["hospital_id"];
         // 登録
         $review = Model_Db_Thospitalreview::forge();
         $review->t_hospital_review_hospital_id = $hospitalId;
         $review->t_hospital_review_nickname = $param["nickname"];
         $review->t_hospital_review_message = $param["message"];
         $review->t_hospital_review_status = ReviewStatus::CLOSED;
         $review->t_hospital_review_created_at = System::now();
         if ($review->save() == 0) {
             throw new Exception("病院評価登録に失敗しました");
         }
         DB::query("refresh materialized view v_hospital_review")->execute();
         Cookie::set("review_" . $hospitalId, $hospitalId, Config::get("site.expire.review"));
         $this->response();
         DB::commit_transaction();
     } catch (Exception $e) {
         DB::rollback_transaction();
         $this->error($e);
     }
 }
开发者ID:marietta-adachi,项目名称:website,代码行数:31,代码来源:review.php

示例3: action_viewtype

 /**
  * Mmeber setting timeline_view
  * 
  * @access  public
  * @return  Response
  */
 public function action_viewtype()
 {
     $page_name = term('timeline', 'site.view', 'site.setting');
     $val = \Form_MemberConfig::get_validation($this->u->id, 'timeline_viewType');
     if (Input::method() == 'POST') {
         Util_security::check_csrf();
         try {
             if (!$val->run()) {
                 throw new \FuelException($val->show_errors());
             }
             $post = $val->validated();
             \DB::start_transaction();
             \Form_MemberConfig::save($this->u->id, $val, $post);
             \DB::commit_transaction();
             \Session::set_flash('message', $page_name . 'を変更しました。');
             \Response::redirect('member/setting');
         } catch (\FuelException $e) {
             if (\DB::in_transaction()) {
                 \DB::rollback_transaction();
             }
             \Session::set_flash('error', $e->getMessage());
         }
     }
     $this->set_title_and_breadcrumbs($page_name, array('member/setting' => term('site.setting', 'form.update')), $this->u);
     $this->template->content = \View::forge('member/setting/timeline_viewtype', array('val' => $val));
 }
开发者ID:uzura8,项目名称:flockbird,代码行数:32,代码来源:setting.php

示例4: post_update

 /**
  * post_update
  * 
  * @access  public
  * @return  Response (json)
  */
 public function post_update($member_id_to = null, $relation_type = null)
 {
     $this->controller_common_api(function () use($member_id_to, $relation_type) {
         $this->response_body['errors']['message_default'] = sprintf('%sの%sに%sしました。', term('follow'), term('form.update'), term('site.failure'));
         if (!self::check_relation_type($relation_type)) {
             throw new HttpNotFoundException();
         }
         if (!is_null(Input::post('id'))) {
             $member_id_to = (int) Input::post('id');
         }
         $member = Model_Member::check_authority($member_id_to);
         if ($member_id_to == $this->u->id) {
             throw new HttpInvalidInputException();
         }
         $member_relation = Model_MemberRelation::get4member_id_from_to($this->u->id, $member_id_to);
         if (!$member_relation) {
             $member_relation = Model_MemberRelation::forge();
         }
         $prop = 'is_' . $relation_type;
         $status_before = (bool) $member_relation->{$prop};
         $status_after = !$status_before;
         \DB::start_transaction();
         $member_relation->{$prop} = $status_after;
         $member_relation->member_id_to = $member_id_to;
         $member_relation->member_id_from = $this->u->id;
         $member_relation->save();
         \DB::commit_transaction();
         $this->response_body['isFollow'] = (int) $status_after;
         $this->response_body['html'] = $status_after ? sprintf('<span class="glyphicon glyphicon-ok"></span> %s', term('followed')) : term('do_follow');
         $this->response_body['attr'] = $status_after ? array('class' => array('add' => 'btn-primary')) : array('class' => array('remove' => 'btn-primary'));
         $this->response_body['message'] = sprintf('%s%s', term('follow'), $status_after ? 'しました。' : 'を解除しました。');
         return $this->response_body;
     });
 }
开发者ID:uzura8,项目名称:flockbird,代码行数:40,代码来源:api.php

示例5: post_upload

 /**
  * Upload images
  * 
  * @access  public
  * @return  Response (json|html)
  * @throws  Exception in Controller_Base::controller_common_api
  * @see  Controller_Base::controller_common_api
  */
 public function post_upload($parent_id = null)
 {
     $this->api_accept_formats = array('html', 'json');
     $this->api_not_check_csrf = true;
     $this->controller_common_api(function () use($parent_id) {
         $upload_type = 'img';
         $news = \News\Model_News::check_authority($parent_id);
         if (!in_array($this->format, array('html', 'json'))) {
             throw new HttpNotFoundException();
         }
         $thumbnail_size = \Input::post('thumbnail_size');
         if (!\Validation::_validation_in_array($thumbnail_size, array('M', 'S'))) {
             throw new \HttpInvalidInputException('Invalid input data');
         }
         $insert_target = \Input::post('insert_target');
         $is_insert_body_image = conf('image.isInsertBody', 'news');
         $options = \Site_Upload::get_upload_handler_options($this->u->id, true, false, 'nw', $parent_id, true, 'img', $is_insert_body_image);
         $uploadhandler = new \MyUploadHandler($options, false);
         \DB::start_transaction();
         $files = $uploadhandler->post(false);
         $files['files'] = \News\Model_NewsImage::save_images($parent_id, $files['files']);
         \DB::commit_transaction();
         $files['upload_type'] = $upload_type;
         $files['thumbnail_size'] = $thumbnail_size;
         $files['insert_target'] = $insert_target;
         $files['model'] = 'news';
         $this->set_response_body_api($files, $this->format == 'html' ? 'filetmp/_parts/upload_images' : null);
     });
 }
开发者ID:uzura8,项目名称:flockbird,代码行数:37,代码来源:api.php

示例6: delete_timeline4id

 public static function delete_timeline4id($timeline_id)
 {
     $delete_target_notice_cache_member_ids = array();
     $writable_connection = \MyOrm\Model::connection(true);
     \DBUtil::set_connection($writable_connection);
     \DB::start_transaction();
     if (is_enabled('notice')) {
         \Notice\Site_NoOrmModel::delete_member_watch_content_multiple4foreign_data('timeline', $timeline_id);
         $notice_ids = \Notice\Site_NoOrmModel::get_notice_ids4foreign_data('timeline', $timeline_id);
         $delete_target_notice_cache_member_ids = \Notice\Site_NoOrmModel::get_notice_status_member_ids4notice_ids($notice_ids);
         \Notice\Site_NoOrmModel::delete_notice_multiple4ids($notice_ids);
     }
     if (!\DB::delete('timeline')->where('id', $timeline_id)->execute()) {
         throw new \FuelException('Failed to delete timeline. id:' . $timeline_id);
     }
     \DB::commit_transaction();
     \DBUtil::set_connection(null);
     // delete caches
     if ($delete_target_notice_cache_member_ids) {
         foreach ($delete_target_notice_cache_member_ids as $member_id) {
             \Notice\Site_Util::delete_unread_count_cache($member_id);
         }
     }
     Site_Util::delete_cache($timeline_id);
 }
开发者ID:uzura8,项目名称:flockbird,代码行数:25,代码来源:noormmodel.php

示例7: action_edit

 /**
  * Mmeber_profile edit
  * 
  * @access  public
  * @return  Response
  */
 public function action_edit($type = null)
 {
     list($type, $is_regist) = self::validate_type($type, $this->u->id);
     $form_member_profile = new Form_MemberProfile($type == 'regist' ? 'regist-config' : 'config', $this->u);
     $form_member_profile->set_validation();
     if (\Input::method() == 'POST') {
         \Util_security::check_csrf();
         try {
             $form_member_profile->validate(true);
             \DB::start_transaction();
             $form_member_profile->seve();
             if ($is_regist) {
                 Model_MemberConfig::delete_value($this->u->id, 'terms_un_agreement');
             }
             \DB::commit_transaction();
             $message = $is_regist ? sprintf('%sが%sしました。', term('site.registration'), term('form.complete')) : term('profile') . 'を編集しました。';
             $redirect_uri = $is_regist ? $this->after_auth_uri : 'member/profile';
             \Session::set_flash('message', $message);
             \Response::redirect($redirect_uri);
         } catch (\FuelException $e) {
             if (\DB::in_transaction()) {
                 \DB::rollback_transaction();
             }
             \Session::set_flash('error', $e->getMessage());
         }
     }
     $this->set_title_and_breadcrumbs(term('profile') . term($is_regist ? 'site.registration' : 'form.edit'), $is_regist ? array() : array('member/profile' => term('common.my', 'profile')), $is_regist ? null : $this->u);
     $this->template->content = View::forge('member/profile/edit', array('is_regist' => $is_regist, 'val' => $form_member_profile->get_validation(), 'member_public_flags' => $form_member_profile->get_member_public_flags(), 'profiles' => $form_member_profile->get_profiles(), 'member_profile_public_flags' => $form_member_profile->get_member_profile_public_flags()));
 }
开发者ID:uzura8,项目名称:flockbird,代码行数:35,代码来源:profile.php

示例8: action_index

 /**
  * Mmeber setting viewtype
  * 
  * @access  public
  * @return  Response
  */
 public function action_index()
 {
     $page_name = term('notice', 'site.setting');
     $val = \Form_MemberConfig::get_validation($this->u->id, 'notice', 'Notice');
     if (\Input::method() == 'POST') {
         \Util_security::check_csrf();
         try {
             if (!$val->run()) {
                 throw new \FuelException($val->show_errors());
             }
             $post = $val->validated();
             \DB::start_transaction();
             \Form_MemberConfig::save($this->u->id, $val, $post);
             \DB::commit_transaction();
             \Session::set_flash('message', $page_name . 'を変更しました。');
             \Response::redirect('member/setting');
         } catch (\FuelException $e) {
             if (\DB::in_transaction()) {
                 \DB::rollback_transaction();
             }
             \Session::set_flash('error', $e->getMessage());
         }
     }
     $this->set_title_and_breadcrumbs($page_name, array('member/setting' => term('site.setting', 'form.update')), $this->u);
     $this->template->content = \View::forge('member/setting/_parts/form', array('val' => $val, 'label_size' => 5, 'form_params' => array('common' => array('radio' => array('layout_type' => 'grid')))));
 }
开发者ID:uzura8,项目名称:flockbird,代码行数:32,代码来源:setting.php

示例9: run

 /**
  * 
  * @param type $count
  * @throws Exception
  */
 public function run($type = "")
 {
     $tran = array("address" => false);
     $tran = @$tran[$type];
     if (is_null($tran)) {
         Log::error("{$type} migration nothing");
         return;
     }
     if ($tran) {
         DB::start_transaction();
     }
     try {
         $this->{$type}();
         DB::query("refresh materialized view v_hospital")->execute();
         DB::query("refresh materialized view v_hospital_access_time_from_station")->execute();
         DB::query("refresh materialized view v_hospital_evaluate")->execute();
         DB::query("refresh materialized view v_hospital_access")->execute();
         DB::query("refresh materialized view v_hospital_review")->execute();
         if ($tran) {
             DB::commit_transaction();
         }
         Log::error("{$type} migration finish");
     } catch (Exception $e) {
         if ($tran) {
             DB::rollback_transaction();
         }
         Logger::error($e);
         throw $e;
     }
 }
开发者ID:marietta-adachi,项目名称:website,代码行数:35,代码来源:datamigration.php

示例10: action_edit

 public function action_edit()
 {
     $lUserData = Input::post('user', null);
     $lAvatar = Input::post('avatar', null);
     $lDeleteAvatar = Input::post('delete_avatar', null);
     if (empty($lUserData)) {
         die(json_encode(['status' => 'error', 'message' => 'Empty data for updating user'], JSON_UNESCAPED_UNICODE));
     }
     $lIsOwner = $lUserData['username'] == $this->current_user['username'];
     if ((empty($lUserData['username']) || !$lIsOwner) && !$this->is_admin) {
         die(json_encode(['status' => 'error', 'message' => 'Access denied'], JSON_UNESCAPED_UNICODE));
     }
     $lUserName = $lUserData['username'];
     unset($lUserData['username']);
     try {
         DB::start_transaction();
         $lOldData = Auth::get_profile_fields();
         if (!empty($lAvatar)) {
             $lNewAvatar = FileHandler::prepareFiles($lAvatar, FileHandler::tempFolder());
             foreach ($lNewAvatar as $lVal) {
                 $lUserData['avatar_id'] = Model_Avatars::add(['file_name' => $lVal]);
                 break;
             }
             if (!empty($lOldData['avatar_id'])) {
                 $lToDeleteAvatar = Model_Avatars::getById($lOldData['avatar_id']);
                 Model_Avatars::delete($lOldData['avatar_id']);
             }
         }
         if (!empty($lDeleteAvatar) && empty($lAvatar)) {
             $lOldAvatar = Model_Avatars::getById($lOldData['avatar_id']);
             foreach ($lDeleteAvatar as $lVal) {
                 if ($lVal != $lOldData['avatar_id']) {
                     break;
                 }
                 $lToDeleteAvatar = $lOldAvatar;
                 Model_Avatars::delete($lVal);
                 $lUserData['avatar_id'] = '';
                 break;
             }
         }
         $lResult = Auth::update_user($lUserData, $lUserName);
         if (!empty($lNewAvatar)) {
             FileHandler::moveFiles($lNewAvatar, FileHandler::tempFolder(), FileHandler::AVATAR_FOLDER);
         }
         if (!empty($lToDeleteAvatar)) {
             FileHandler::deleteFiles([FileHandler::AVATAR_FOLDER . $lToDeleteAvatar['file_name']]);
         }
         DB::commit_transaction();
     } catch (Exception $e) {
         DB::rollback_transaction();
         die(json_encode(['status' => 'error', 'message' => 'Error ' . $e], JSON_UNESCAPED_UNICODE));
     }
     if ($lResult) {
         die(json_encode(['status' => 'ok'], JSON_UNESCAPED_UNICODE));
     }
     die(json_encode(['status' => 'error', 'message' => 'Fields not were updated'], JSON_UNESCAPED_UNICODE));
 }
开发者ID:FTTA,项目名称:devels,代码行数:57,代码来源:Users.php

示例11: add_relation

 /**
  * add_relation 
  * @return type
  */
 public static function add_relation()
 {
     try {
         if (!self::validation_add_relation()) {
             return self::error();
         }
         # lat&lng -> geohash
         $geohash = Util_Geohash::encode(Input::post('lat'), Input::post('lng'));
         # transaction
         DB::start_transaction();
         # shop_id指定
         if (is_null(Input::post('shop_id'))) {
             # new shop
             $shop_id = Model_Shop::add(Input::post('shop_name'));
         } else {
             $data = Model_Shop::get_by_pk("shop", Input::post('shop_id'));
             if (!$data) {
                 throw new Exception('shop_id ' . Input::post('shop_id') . " is not exsits.");
             }
             $shop_id = $data['shop_id'];
         }
         # new shop geo add
         if (is_null(Input::post('shop_id'))) {
             if (!self::add($shop_id, Input::post('lat'), Input::post('lng'), $geohash)) {
                 throw new Exception("insert geo fail.");
             }
         }
         # fileupload & setting
         self::$file_name = self::file_upload($shop_id);
         self::$file_path = self::UPLOAD_DIR . Input::post('shop_id') . DS . self::$file_name;
         if (!self::$file_name) {
             throw new Exception('file upload fail.');
         }
         # image resize
         # todo
         # image add
         if (!Model_Image::add($shop_id, Input::post('user_id'), self::$file_name)) {
             throw new Exception("insert image fail.");
         }
         # commit
         DB::commit_transaction();
         # success
         $data = ['status' => CREATED];
     } catch (Exception $ex) {
         # 画像ファイルが存在すれば削除
         if (is_file(self::$file_path)) {
             unlink(self::$file_path);
         }
         # rollback
         DB::rollback_transaction();
         $data = ['status' => DATABASE_ERROR, 'message' => '[database error]insert table fail.'];
         Log::error($ex);
     }
     return $data;
 }
开发者ID:leprafujii,项目名称:api,代码行数:59,代码来源:geo.php

示例12: addClient

 /**
  * ユーザー情報の登録処理
  * 
  * @param array $userInfo ユーザー情報
  */
 public function addClient($userInfo)
 {
     try {
         DB::start_transaction();
         // OpenIDとユーザー情報紐付く処理
         DB::commit_transaction();
     } catch (Exception $ex) {
         DB::rollback_transaction();
         return NULL;
     }
 }
开发者ID:Kim20110119,项目名称:FuelPHP_Opauth,代码行数:16,代码来源:auth.php

示例13: clean

 /**
  * clean queues
  *
  */
 public function clean()
 {
     try {
         \DB::start_transaction();
         $query = \DB::delete('task_queues')->where('job_status', \Model_TaskQueue::STATUS_SUCCESS)->where('updated_at', '<=', date('Y-m-d', strtotime(\Config::get('queue.success_queue_delete_term'))));
         $query->execute();
         \DB::commit_transaction();
     } catch (\Exception $e) {
         \DB::rollback_transaction();
     }
 }
开发者ID:hinashiki,项目名称:fuelphp-queue,代码行数:15,代码来源:queues.php

示例14: updateDB

 public function updateDB()
 {
     //Get the current values
     $oldValues = $this->getAllExisting();
     $this->dbObj->start_transaction();
     try {
         //Determine the diff between existing values and new values
         $addedTags = array();
         $removedTags = array();
         $changedTags = array();
         if (false !== $oldValues) {
             foreach ($oldValues as $tag => $v) {
                 $changes = array();
                 if (array_key_exists($tag, $this->updateInfo)) {
                     $changes = $this->dataUpdated($oldValues[$tag], $this->updateInfo[$tag]);
                     if (count($changes) > 0) {
                         $changedTags[$tag] = $changes;
                     }
                 } else {
                     $removedTags[] = $tag;
                 }
             }
             //Check if any new rows were added
             foreach ($this->updateInfo as $u) {
                 if (!array_key_exists($u->getTag(), $oldValues)) {
                     $addedTags[] = $u->getTag();
                 }
             }
         }
         $this->changedTags = $changedTags;
         $this->addedTags = $addedTags;
         $this->removedTags = $removedTags;
         //Add the new rows as new version
         $this->add($this->updateInfo);
     } catch (DBException $ex) {
         $this->dbObj->rollback();
         throw new Exception($ex->getMessage());
     }
     $this->dbObj->end_transaction();
 }
开发者ID:nikhilpatel1989,项目名称:Transporter-Server,代码行数:40,代码来源:TableUpdate.php

示例15: common_post_update

 /**
  * 以下、admin_api 共通 controller
  * 
  */
 protected function common_post_update($field, $accepts_fields)
 {
     $this->controller_common_api(function () use($field, $accepts_fields) {
         if (!$field || !in_array($field, $accepts_fields)) {
             throw new \HttpNotFoundException();
         }
         \DB::start_transaction();
         $method = 'update_' . $field;
         $result = (bool) $this->{$method}();
         \DB::commit_transaction();
         $this->set_response_body_api(array('result' => $result));
     });
 }
开发者ID:uzura8,项目名称:flockbird,代码行数:17,代码来源:api.php


注:本文中的DB::start_transaction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。