Giter VIP home page Giter VIP logo

Comments (5)

yajra avatar yajra commented on July 17, 2024

would it be possible to paste here the actual/snippet of the transaction code?

On the other hand, based on examples, since you are using 2 connections, I think you should also make 2 transaction which depends on the other. Not sure though coz i haven't this scenario on actual.

Maybe try doing something like below:
[start db1 transaction]
[start db2 transaction]
[insert on db2]
[selec db1]
[insert db2]
[rollback if fails]

// default connection
DB::transaction(function($conn){
    DB::connection('db2')->transaction(function($conn){
        // do insert
        // do select
        // do insert
    });
});

Way back, I think i stumbled to an issue on laravel framework with nested transactions but can't seem to find it anymore since issues are now closed on it's github site.

Hope this helps!

from laravel-oci8.

yajra avatar yajra commented on July 17, 2024

You can also try playing with the PDO object

try {
    DB::connection()->getPdo()->beginTransaction();
    // database queries here
    DB::connection()->getPdo()->commit();
} catch (\PDOException $e) {
    // Woopsy
    DB::connection()->getPdo()->rollBack();
}

from laravel-oci8.

reindeer77 avatar reindeer77 commented on July 17, 2024

This is how I was trying to check the scenario, very basic, I'm gonna have some tests with your suggestions and let you know, thanks!

DB::transaction(function(){
            //RO connection
            //$company = Company::find(1);

            $username = array(
                'username' => 'alex.company'
            );
            //WO connection
            User::create($username);

            $company = Company::find(1);
            $username = array(
                //adding an error to rise an exception
                'usermame' => 'tom.company',
            );
            //WO connection
            User::create($username);

        });

from laravel-oci8.

reindeer77 avatar reindeer77 commented on July 17, 2024

Tried different scenarios and it seems your suggestion works flawlessy, tnx! :)
I'm a bit puzzled since in fact the default connection is the one on which I wanted the rollback and the only one declared.

// default connection
DB::transaction(function($conn){
    DB::connection('db2')->transaction(function($conn){
        // do insert
        // do select
        // do insert
    });
});

from laravel-oci8.

yajra avatar yajra commented on July 17, 2024

There seems to be no problem on your code but to be sure try enabling app.debug=true so you can further see the error logs.

Anyways, good to hear that my suggestion works! Closing this issue now. :)

from laravel-oci8.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.