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;








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










share|improve this question
























  • 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

















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










share|improve this question
























  • 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













0












0








0


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










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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

















  • 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












1 Answer
1






active

oldest

votes


















0














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();






share|improve this answer























  • Does it work for you?

    – Jonas Staudenmeir
    Apr 4 at 23:26










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
);



);













draft saved

draft discarded


















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









0














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();






share|improve this answer























  • Does it work for you?

    – Jonas Staudenmeir
    Apr 4 at 23:26















0














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();






share|improve this answer























  • Does it work for you?

    – Jonas Staudenmeir
    Apr 4 at 23:26













0












0








0







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();






share|improve this answer













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();







share|improve this answer












share|improve this answer



share|improve this answer










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

















  • 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








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.



















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현