Laravel 5.8 initiate DB::beginTransaction() on a different database per userLaravel database Design and RelationshipRollback in laravel has no effectLaravel 5.8 showing 404 Not Found errorsIs it possible to “lock” a session in Laravel 5.8?Laravel 5.8 dropdown valueComment Table Giving SQLSTATE[42S02] laravel 5.8Laravel 5.8 refresh database without losing data in tables already existLaravel 5.8 get tables belonging to a userLaravel 5.8 Manual user approval?Php artisan migrate in laravel 5.8 with Ubuntu 18
"This used to be my phone number"
Which GPUs to get for Mathematical Optimization (if any)?
What could make large expeditions ineffective for exploring territory full of dangers and valuable resources?
Are there any satellites in geosynchronous but not geostationary orbits?
"Je suis petite, moi?", purpose of the "moi"?
How much solution to fill Paterson Universal Tank when developing film?
Does unblocking power bar outlets through short extension cords increase fire risk?
Authorship dispute on a paper that came out of a final report of a course?
How do you name this compound using IUPAC system (including steps)?
Did Hitler say this quote about homeschooling?
What is a Romeo Word™?
We get more abuse than anyone else
I have found a mistake on someone's code published online: what is the protocol?
Why teach C using scanf without talking about command line arguments?
In this iconic lunar orbit rendezvous photo of John Houbolt, why do arrows #5 and #6 point the "wrong" way?
Why do jet engines sound louder on the ground than inside the aircraft?
How did Jayne know when to shoot?
What is actually sent/loaded to a microcontroller / stm32
Last-minute canceled work-trip mean I'll lose thousands of dollars on planned vacation
How can I help our ranger feel special about her beast companion?
What makes MOVEQ quicker than a normal MOVE in 68000 assembly?
When will the last unambiguous evidence of mankind disappear?
Is it possible to have a career in SciComp without contributing to arms research?
Making a Dataset that emulates `ls -tlra`?
Laravel 5.8 initiate DB::beginTransaction() on a different database per user
Laravel database Design and RelationshipRollback in laravel has no effectLaravel 5.8 showing 404 Not Found errorsIs it possible to “lock” a session in Laravel 5.8?Laravel 5.8 dropdown valueComment Table Giving SQLSTATE[42S02] laravel 5.8Laravel 5.8 refresh database without losing data in tables already existLaravel 5.8 get tables belonging to a userLaravel 5.8 Manual user approval?Php artisan migrate in laravel 5.8 with Ubuntu 18
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have an app where the user owns their own DB. I am creating a record save which includes a relationship (so two tables updated) and I want to wrap the execution with DB::transaction()
. The only issue is the DB name must change user by user.
The $user->db_name
contains the data expected and it works well with other selection queries.
If I do this it fails with Call to a member function beginTransaction() on null
DB::disconnect(config('database.default'));
Config::set('database.connections.mysql.database', $user->db_name);
DB::beginTransaction();
try
.
.
$data1->create();
$data2->create();
DB::commit();
catch (Exception $e)
DB::rollback();
If I do this and force a fail on the second create statement, it keeps the record in table from the first create.
DB::beginTransaction();
try
DB::disconnect(config('database.default'));
Config::set('database.connections.mysql.database', $user->db_name);
.
.
$data1->create();
$data2->create();
DB::commit();
catch (Exception $e)
DB::rollback();
How do I achieve the DB change and transaction with rollback on failure against a user's db? Thanks
eloquent laravel-5.8
add a comment |
I have an app where the user owns their own DB. I am creating a record save which includes a relationship (so two tables updated) and I want to wrap the execution with DB::transaction()
. The only issue is the DB name must change user by user.
The $user->db_name
contains the data expected and it works well with other selection queries.
If I do this it fails with Call to a member function beginTransaction() on null
DB::disconnect(config('database.default'));
Config::set('database.connections.mysql.database', $user->db_name);
DB::beginTransaction();
try
.
.
$data1->create();
$data2->create();
DB::commit();
catch (Exception $e)
DB::rollback();
If I do this and force a fail on the second create statement, it keeps the record in table from the first create.
DB::beginTransaction();
try
DB::disconnect(config('database.default'));
Config::set('database.connections.mysql.database', $user->db_name);
.
.
$data1->create();
$data2->create();
DB::commit();
catch (Exception $e)
DB::rollback();
How do I achieve the DB change and transaction with rollback on failure against a user's db? Thanks
eloquent laravel-5.8
Maybe it's a good idea to not create a separate database for each user? There might be a reason why this is not properly working in Laravel.
– Dees Oomens
Mar 26 at 13:52
add a comment |
I have an app where the user owns their own DB. I am creating a record save which includes a relationship (so two tables updated) and I want to wrap the execution with DB::transaction()
. The only issue is the DB name must change user by user.
The $user->db_name
contains the data expected and it works well with other selection queries.
If I do this it fails with Call to a member function beginTransaction() on null
DB::disconnect(config('database.default'));
Config::set('database.connections.mysql.database', $user->db_name);
DB::beginTransaction();
try
.
.
$data1->create();
$data2->create();
DB::commit();
catch (Exception $e)
DB::rollback();
If I do this and force a fail on the second create statement, it keeps the record in table from the first create.
DB::beginTransaction();
try
DB::disconnect(config('database.default'));
Config::set('database.connections.mysql.database', $user->db_name);
.
.
$data1->create();
$data2->create();
DB::commit();
catch (Exception $e)
DB::rollback();
How do I achieve the DB change and transaction with rollback on failure against a user's db? Thanks
eloquent laravel-5.8
I have an app where the user owns their own DB. I am creating a record save which includes a relationship (so two tables updated) and I want to wrap the execution with DB::transaction()
. The only issue is the DB name must change user by user.
The $user->db_name
contains the data expected and it works well with other selection queries.
If I do this it fails with Call to a member function beginTransaction() on null
DB::disconnect(config('database.default'));
Config::set('database.connections.mysql.database', $user->db_name);
DB::beginTransaction();
try
.
.
$data1->create();
$data2->create();
DB::commit();
catch (Exception $e)
DB::rollback();
If I do this and force a fail on the second create statement, it keeps the record in table from the first create.
DB::beginTransaction();
try
DB::disconnect(config('database.default'));
Config::set('database.connections.mysql.database', $user->db_name);
.
.
$data1->create();
$data2->create();
DB::commit();
catch (Exception $e)
DB::rollback();
How do I achieve the DB change and transaction with rollback on failure against a user's db? Thanks
eloquent laravel-5.8
eloquent laravel-5.8
edited Mar 26 at 16:08
Jonas Staudenmeir
15.3k2 gold badges12 silver badges43 bronze badges
15.3k2 gold badges12 silver badges43 bronze badges
asked Mar 26 at 10:42
TheRealPapaTheRealPapa
1,8955 gold badges33 silver badges88 bronze badges
1,8955 gold badges33 silver badges88 bronze badges
Maybe it's a good idea to not create a separate database for each user? There might be a reason why this is not properly working in Laravel.
– Dees Oomens
Mar 26 at 13:52
add a comment |
Maybe it's a good idea to not create a separate database for each user? There might be a reason why this is not properly working in Laravel.
– Dees Oomens
Mar 26 at 13:52
Maybe it's a good idea to not create a separate database for each user? There might be a reason why this is not properly working in Laravel.
– Dees Oomens
Mar 26 at 13:52
Maybe it's a good idea to not create a separate database for each user? There might be a reason why this is not properly working in Laravel.
– Dees Oomens
Mar 26 at 13:52
add a comment |
1 Answer
1
active
oldest
votes
Use reconnect()
:
DB::reconnect(config('database.default'));
Config::set('database.connections.mysql.database', $user->db_name);
DB::beginTransaction();
try
.
.
$data1->create();
$data2->create();
DB::commit();
catch (Exception $e)
DB::rollback();
Does it work for you?
– Jonas Staudenmeir
Apr 4 at 23:26
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55355169%2flaravel-5-8-initiate-dbbegintransaction-on-a-different-database-per-user%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Use reconnect()
:
DB::reconnect(config('database.default'));
Config::set('database.connections.mysql.database', $user->db_name);
DB::beginTransaction();
try
.
.
$data1->create();
$data2->create();
DB::commit();
catch (Exception $e)
DB::rollback();
Does it work for you?
– Jonas Staudenmeir
Apr 4 at 23:26
add a comment |
Use reconnect()
:
DB::reconnect(config('database.default'));
Config::set('database.connections.mysql.database', $user->db_name);
DB::beginTransaction();
try
.
.
$data1->create();
$data2->create();
DB::commit();
catch (Exception $e)
DB::rollback();
Does it work for you?
– Jonas Staudenmeir
Apr 4 at 23:26
add a comment |
Use reconnect()
:
DB::reconnect(config('database.default'));
Config::set('database.connections.mysql.database', $user->db_name);
DB::beginTransaction();
try
.
.
$data1->create();
$data2->create();
DB::commit();
catch (Exception $e)
DB::rollback();
Use reconnect()
:
DB::reconnect(config('database.default'));
Config::set('database.connections.mysql.database', $user->db_name);
DB::beginTransaction();
try
.
.
$data1->create();
$data2->create();
DB::commit();
catch (Exception $e)
DB::rollback();
answered Apr 1 at 3:30
Jonas StaudenmeirJonas Staudenmeir
15.3k2 gold badges12 silver badges43 bronze badges
15.3k2 gold badges12 silver badges43 bronze badges
Does it work for you?
– Jonas Staudenmeir
Apr 4 at 23:26
add a comment |
Does it work for you?
– Jonas Staudenmeir
Apr 4 at 23:26
Does it work for you?
– Jonas Staudenmeir
Apr 4 at 23:26
Does it work for you?
– Jonas Staudenmeir
Apr 4 at 23:26
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55355169%2flaravel-5-8-initiate-dbbegintransaction-on-a-different-database-per-user%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Maybe it's a good idea to not create a separate database for each user? There might be a reason why this is not properly working in Laravel.
– Dees Oomens
Mar 26 at 13:52