laravel-oci8 icon indicating copy to clipboard operation
laravel-oci8 copied to clipboard

DB rollBack not working properly

Open xStarman opened this issue 6 years ago • 2 comments

Summary of problem or feature request

Even using rollback the data is updated in the database

Code snippet of problem

    \DB::beginTransaction();
        AclUsers::where('id', 1538)->update(['name' => 'EDSON ALVES DE OLIVEIRA J']);
    \DB::rollBack();

image

System details

  • Operating System PRETTY_NAME="Debian GNU/Linux 9 (stretch)" NAME="Debian GNU/Linux" VERSION_ID="9" VERSION="9 (stretch)" ID=debian
  • PHP Version PHP 7.2.16
  • Laravel Version 5.8
  • Laravel-OCI8 Version 5.8

xStarman avatar Apr 03 '19 19:04 xStarman

I noticed that using DB :: statement works:

\DB::transaction(function($conn){          
      \DB::statement("update acl_users set name = 'pirilampo' where id = 1538");
\DB::rollBack();

Maybe this help you understand what is going on.

My model:

<?php
    namespace App\Models;
    use Illuminate\Database\Eloquent\Model;

    class AclUsers extends Model{
        protected $connection = 'web';
        protected $table = 'acl_users';
        public $timestamps = false;
        protected $hidden = ['password', 'hash_temp'];
    }

xStarman avatar Apr 04 '19 13:04 xStarman

help my please. the rollback with the next option not working

function myFunction($p) {
        return DB::transaction(function($conn) use ($p) {
                    try {
                        $pdo = $conn->getPdo();
                        $sql = "BEGIN VLS_PK.INSERT_VLC_SP(:P_ID,:P_SMS); END;";
                        $stmt = $pdo->prepare($sql);
                        $stmt->bindParam(':P_ID', $p->id, PDO::PARAM_INT);
                        $stmt->bindParam(':P_SMS', $p->sms, PDO::PARAM_STR);
                        $stmt->execute();                        
                        $sql2 = "BEGIN VLS_PK.INSERT_VLB_SP(:P_ID,:P_SMS); END;";
                        $stmt2 = $pdo->prepare($sql2);
                        $stmt2->bindParam(':P_ID', $p->id, PDO::PARAM_INT);
                        $stmt2->bindParam(':P_SMS', $p->sms, PDO::PARAM_STR);
                        $stmt2->execute();
                        return true;
                    } catch (\Throwable $e) {
                        Log::error('myClass.myFunction' . PHP_EOL . $e->getMessage());
                        return false;
                    }
                });
    }

Sithcarlos avatar Aug 13 '19 22:08 Sithcarlos

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Oct 27 '22 03:10 github-actions[bot]

This issue was closed because it has been inactive for 7 days since being marked as stale.

github-actions[bot] avatar Nov 04 '22 03:11 github-actions[bot]