本文整理汇总了PHP中DB::beginTransaction方法的典型用法代码示例。如果您正苦于以下问题:PHP DB::beginTransaction方法的具体用法?PHP DB::beginTransaction怎么用?PHP DB::beginTransaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DB
的用法示例。
在下文中一共展示了DB::beginTransaction方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: DB
/**
*
* @return \Hypersistence\Core\DB
*/
public static function &getDBConnection()
{
if (!is_null(self::$conn) && self::$conn instanceof DB) {
return self::$conn;
} else {
$conf = simplexml_load_file(__DIR__ . '/../dbconf.xml');
self::$conn = new DB("{$conf->dbms}:host={$conf->host};dbname={$conf->database};charset={$conf->charset}", $conf->username, $conf->password, array(self::ATTR_PERSISTENT => true, self::ATTR_STATEMENT_CLASS => array('\\Hypersistence\\Core\\Statement'), self::ATTR_PERSISTENT => false));
if (!self::$conn->inTransaction()) {
self::$conn->beginTransaction();
}
return self::$conn;
}
}
示例2: postRegistroEmpresas
public function postRegistroEmpresas()
{
DB::beginTransaction();
try {
$empresa = new LandingEmpresa();
$empresa->razon_social = ucwords(strtolower(Input::get('empresa_razonsocial')));
$empresa->ruc = Input::get('empresa_ruc');
$empresa->inscritos = Input::get('empresa_inscritos');
$empresa->domicilio = Input::get('empresa_domicilio');
$empresa->email = Input::get('empresa_email');
$empresa->telefono = Input::get('empresa_telefono');
$empresa->celular = Input::get('empresa_celular');
$empresa->curso = Input::get('empresa_curso');
$empresa->comentario = Input::get('empresa_comentario');
$empresa->recibir_noticias = Input::get('empresa_informacion');
$empresa->ip = Request::getClientIp(true);
$empresa->save();
$respuesta = array('status' => 'ok');
DB::commit();
} catch (\Exception $e) {
DB::rollback();
$respuesta = array('status' => 'error', 'messages' => 'Exception with msg: ' . $e->getMessage());
}
return Response::json($respuesta, 200);
}
示例3: newCategory
public function newCategory()
{
$validate = new Validate();
$validated = $validate->Validate_Category();
$nameToSlug = $this->nameToSlug($validated);
if (\Auth::check()) {
if ($validated->passes() && $nameToSlug === true) {
$slug = \Input::get('name');
$slug = preg_replace('#[ -]+#', '-', $slug);
$slug = strtolower($slug);
\DB::beginTransaction();
try {
$item = new \MenuCategory();
$item->menu_category_name = \Input::get('name');
$item->menu_category_slug = $slug;
$item->save();
} catch (ValidationException $e) {
DB::rollback();
throw $e;
}
\DB::commit();
return \Redirect::to('admin/category/edit/' . $slug)->with('message', '<div class="alert alert-dismissible alert-success alert-link"><button type="button" class="close" data-dismiss="alert">×</button>Saved!</p></div>');
}
if ($nameToSlug === false) {
return \View::make('categories.new')->withErrors($validated)->withInput(array('name'))->with('message', '<p class="alert alert-dismissible alert-danger alert-link">That category already exists!');
}
return \View::make('categories.new')->withErrors($validated)->withInput(array('name'));
}
return \Redirect::to('admin');
}
示例4: deleteCategoryInfo
public function deleteCategoryInfo($slug)
{
$results = \MenuCategory::where('menu_category_slug', '=', $slug)->get();
foreach ($results as $result) {
$id = $result->menu_category_id;
}
$items_using_cat = \MenuItem::where('menu_item_category_fk', '=', $id)->get();
foreach ($items_using_cat as $item_using_cat) {
if ($item_using_cat) {
return \Redirect::to("admin/category/edit/{$slug}")->with('message', '<div class="alert alert-dismissible alert-danger alert-link">Unable to delete category. Please make sure no items are using this category.</p></div>');
}
}
//if an item exists that has this cat's fk, reload the page with an error
if (\Auth::check()) {
\DB::beginTransaction();
try {
$statement = \MenuCategory::find($id);
$statement->delete();
} catch (ValidationException $e) {
DB::rollback();
throw $e;
}
\DB::commit();
return \Redirect::to('admin')->with('message', '<div class="alert alert-dismissible alert-success alert-link">Category has been deleted</p></div>');
}
return \Redirect::to('admin');
}
示例5: postAdminSettings
public function postAdminSettings()
{
$title = Input::get('title');
$about = Input::get('about');
$address = Input::get('address');
$phone = Input::get('phone');
$email = Input::get('email');
$location = Input::get('location');
$file = Input::file('file');
$destinationPath = 'uploads';
$filename = DB::table('settings')->first()->logo;
// If the uploads fail due to file system, you can try doing public_path().'/uploads'
if ($file) {
$filename = time() . $file->getClientOriginalName();
$extension = $file->getClientOriginalExtension();
$upload_success = Input::file('file')->move($destinationPath, $filename);
}
DB::beginTransaction();
try {
DB::table('settings')->where('id', 1)->update(array('title' => $title, 'logo' => $filename, 'about' => $about, 'address' => $address, 'phone' => $phone, 'email' => $email, 'location' => $location));
DB::commit();
return Redirect::route('getAdminSettings')->with(array('status' => 'success'));
} catch (\Exception $e) {
DB::rollback();
return Redirect::route('getAdminSettings')->with(array('status' => 'error'));
}
}
示例6: updateRestaurantInfo
public function updateRestaurantInfo()
{
$user = \Auth::user();
$id = $user->user_id;
$restaurant = \Restaurant::all();
foreach ($restaurant as $rest) {
$restaurant_name = $rest->restaurant_name;
$restaurant_street_1 = $rest->restaurant_street_1;
$restaurant_street_2 = $rest->restaurant_street_2;
$restaurant_phone = $rest->restaurant_phone;
$restaurant_email = $rest->restaurant_email;
$restaurant_id = $rest->restaurant_info_id;
}
\DB::beginTransaction();
try {
$statement = \Restaurant::find($restaurant_id);
$statement->restaurant_name = \Input::get('name');
$statement->restaurant_street_1 = \Input::get('address1');
$statement->restaurant_street_2 = \Input::get('address2');
$statement->restaurant_email = \Input::get('email');
$statement->restaurant_phone = \Input::get('phone');
$statement->user_id_fk = $id;
$statement->save();
} catch (ValidationException $e) {
DB::rollback();
throw $e;
}
\DB::commit();
return \Redirect::to('admin/account/edit/restaurant')->withRestaurantName($restaurant_name)->withRestaurantStreet_1($restaurant_street_1)->withRestaurantStreet_2($restaurant_street_2)->withRestaurantPhone($restaurant_phone)->withRestaurantEmail($restaurant_email)->with('message', '<p class="alert alert-dismissible alert-success alert-link">Saved!' . '</p>');
}
示例7: postEditar
/**
* Update the specified resource in storage.
* POST /cargo/editar
*
* @return Response
*/
public function postEditar()
{
if (Request::ajax()) {
$sql = "";
$cargoId = Input::get('id');
$array = array();
$array['grupo_persona_id'] = Input::get('grupop');
$array['cargo_estrategico_id'] = Input::get('cargo');
$cargo_estrategico = Input::get('cargo');
$array['id'] = $cargoId;
DB::beginTransaction();
DB::table('grupos_cargos')->where('grupo_persona_id', Input::get('grupop'))->update(array('estado' => 0));
for ($i = 0; $i < count($cargo_estrategico); $i++) {
$sql = " SELECT id\n FROM grupos_cargos\n WHERE grupo_persona_id='" . Input::get('grupop') . "'\n AND cargo_estrategico_id='" . $cargo_estrategico[$i] . "'";
$rf = DB::select($sql);
if (count($rf) > 0) {
$cargo = GrupoCargo::find($rf[0]->id);
$cargo->fecha_inicio = Input::get('fecha_inicio');
$cargo->estado = 1;
$cargo->usuario_updated_at = Auth::user()->id;
$cargo->save();
} else {
$cargo = new GrupoCargo();
$cargo->grupo_persona_id = Input::get('grupop');
$cargo->cargo_estrategico_id = $cargo_estrategico[$i];
$cargo->fecha_inicio = Input::get('fecha_inicio');
$cargo->estado = 1;
$cargo->usuario_created_at = Auth::user()->id;
$cargo->save();
}
}
DB::commit();
return Response::json(array('rst' => 1, 'msj' => 'Registro actualizado correctamente'));
}
}
示例8: postValidar
public function postValidar()
{
if (Request::ajax()) {
$personas = Input::get('personas');
DB::beginTransaction();
for ($i = 0; $i < count($personas); $i++) {
$per = explode("_", $personas[$i]);
$mensajeria = Mensajeria::where('activista_id', $per[1])->first();
if (!isset($mensajeria->id)) {
$mensajeria = new Mensajeria();
$mensajeria->activista_id = $per[1];
$mensajeria->usuario_created_at = $this->userID;
} else {
$mensajeria->usuario_updated_at = $this->userID;
}
if ($per[0] == 'celular') {
$mensajeria->cel = $per[2];
$mensajeria->nrollamada = $mensajeria->nrollamada * 1 + 1;
} else {
$mensajeria->email = 1;
$mensajeria->validado = 1;
}
$mensajeria->save();
}
DB::commit();
return Response::json(array('rst' => 1, 'msj' => 'Se registro correctamente'));
}
}
示例9: __construct
public function __construct(\App\Myclasses\Checks\Checker $checker)
{
\DB::beginTransaction();
$this->fail = 0;
$this->checker = $checker;
$this->data = $this->checker->getData();
}
示例10: criar
public function criar(array $dados)
{
\DB::beginTransaction();
try {
$dados['status'] = 0;
if (isset($dados['codigo_cupom'])) {
$cupom = $this->cupomRepository->findByField('codigo', $dados['codigo_cupom'])->first();
$dados['cupom_id'] = $cupom->id;
$cupom->used = 1;
$cupom->save();
unset($dados['codigo_cupom']);
}
$items = $dados['items'];
unset($dados['items']);
$pedido = $this->repository->create($dados);
$total = 0;
foreach ($items as $item) {
$item['preco'] = $this->produtoRepository->find($item['produto_id'])->preco;
$pedido->items()->create($item);
$total += $item['preco'] * $item['quantidade'];
}
$pedido->total = $total;
if (isset($cupom)) {
$pedido->total = $total - $cupom->valor;
}
$pedido->save();
\DB::commit();
return $pedido;
} catch (\Exception $e) {
DB::rollback();
throw $e;
}
}
示例11: store
public function store(StoreDocumentRequest $request)
{
$data = $request->all();
$document = $this->storeService->tracking($data['document_id']);
if (!empty($data['zero'])) {
$this->orderRepository->create($data);
} else {
if ($document['status'] == 2) {
\DB::beginTransaction();
try {
$data['evaluation'] = $this->storeService->evaluation($data);
$this->orderRepository->create($data);
$this->storeService->care($data['document_id']);
\DB::commit();
} catch (\Exception $e) {
\DB::rollback();
throw $e;
}
} else {
\DB::beginTransaction();
try {
$data['evaluation'] = $this->storeService->evaluation($data);
$this->orderRepository->create($data);
\DB::commit();
} catch (\Exception $e) {
\DB::rollback();
throw $e;
}
}
}
Session::put('success', 'Corrigida com sucesso');
return redirect()->route('store.index');
}
示例12: saveBook
public function saveBook(Request $request)
{
\DB::beginTransaction();
$this->cover = $this->upload($request);
$this->title = $request->input('title');
$this->author = $request->input('author');
$this->translator = $request->input('translator');
$this->synopsis = $request->input('synopsis');
$this->origin = $request->input('origin');
$this->publishing_companies_id = $request->input('publishing_companies_id');
$this->language = $request->input('language');
$this->edition = $request->input('edition');
$this->year = $request->input('year');
$this->bar_code = $request->input('bar_code');
$this->isbn = $request->input('isbn');
$this->binding = $request->input('binding');
$this->height = floatval(str_replace(',', '.', $request->input('height')));
$this->width = floatval(str_replace(',', '.', $request->input('width')));
$this->length = floatval(str_replace(',', '.', $request->input('length')));
$this->weight = floatval(str_replace(',', '.', $request->input('weight')));
$this->number_pages = $request->input('number_pages');
if ($this->save()) {
$this->genus()->sync($request->input('genus'));
$success = true;
}
if ($success) {
\DB::commit();
return true;
} else {
\DB::rollback();
return false;
}
}
示例13: postRegister
public function postRegister(Request $request)
{
$dataClient = $request->only('name', 'last_name', 'phone', 'email');
$dataUser = $request->only('email', 'password');
$dataClientAddress = $request->only('id_city', 'address', 'latitude', 'longitude');
$validator = \Validator::make($dataClient, $this->rulesClient);
if ($validator->passes()) {
try {
\DB::beginTransaction();
$dataUser['name'] = $dataClient['name'] . ' ' . $dataClient['last_name'];
$dataUser['type'] = 'client';
$user = $this->userRepo->create($dataUser);
$dataClient['id_user'] = $user->id;
$client = $this->clientRepo->create($dataClient);
$dataClientAddress['id_client'] = $client->id;
$clientAddress = $this->clientAddressRepo->create($dataClientAddress);
$code = 201;
$message = "Cliente Registrado Corectamente";
$success = true;
\DB::commit();
return response()->json(compact('success', 'message', 'client'), $code);
} catch (\Exception $e) {
\DB::rollback();
$code = 500;
$success = false;
$message = 'Error al registrar';
return response()->json(compact('success', 'message'), $code);
}
} else {
$success = false;
$message = $validator->messages();
$code = 400;
return response()->json(compact('success', 'message'), $code);
}
}
示例14: updateBroadcasterProfile
public function updateBroadcasterProfile($request)
{
if ($request->hasFile('logo')) {
$file = $request->file('logo');
$logo = time() . "-" . $file->getClientOriginalName();
$file->move(public_path() . \Config::get('site.broadcasterLogoPath'), $logo);
$this->currentBroadcaster->logo = $logo;
}
$success = false;
\DB::beginTransaction();
try {
$this->currentUser->name = $request->get('name');
if ($request->get('changepass')) {
$this->currentUser->password = \Hash::make(trim($request->get('password')));
}
$this->currentUser->save();
$this->currentBroadcaster->display_name = $request->get('display_name');
$this->currentBroadcaster->company_name = $request->get('company_name');
$this->currentBroadcaster->save();
$success = true;
} catch (\Exception $e) {
\DB::rollback();
}
if ($success) {
\DB::commit();
}
}
示例15: __construct
public function __construct($object, $data)
{
$this->data = $data;
\DB::beginTransaction();
try {
switch ($object) {
case 'star':
$this->toChange = \App\Star::find($data['id']);
$this->address = $this->toChange->address;
$this->changeStar();
$this->finalize();
break;
case 'planet':
$this->toChange = \App\Planet::find($data['id']);
$this->address = $this->toChange->star->address;
$this->changePlanet();
$this->finalize();
break;
case 'bari':
$this->toChange = \App\Bariplanet::find($data['id']);
$this->address = $this->toChange->center->address;
$this->changePlanet();
$this->finalize();
break;
case 'multi':
$this->toChange = \App\Baricenter::find($data['id']);
$this->address = $this->toChange->address;
$this->changeMulti();
$this->finalize();
break;
}
} catch (\PDOException $e) {
$this->rollback();
}
}