CodeIgniter Forums
CI4 Transaction not working on me - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: CI4 Transaction not working on me (/showthread.php?tid=80179)



CI4 Transaction not working on me - dcyilmaz - 09-24-2021

PHP Code:
When a quoted data is receivedit gives an error and the undo operation does not work.
 this page have to 17 but getting error and not rollback. 
$stoklar
=json_decode(file_get_contents('http://myjsondata.com'));
        $db->transBegin();
        foreach ($stoklar->DATA as $key => $w) {
          for ($i=0$i <count($w) ; $i++) {
            $w[$i]=htmlentities(stripslashes($w[$i]));//error was here i should add ,ENT_QUOTES, "UTF-8" i know i but wanna see transaction
          }
          $PRICE_KDV=$w[0];
          $SALEABLE_STOCK=$w[1];
          $PRODUCT_ID=$w[2];
          $PRODUCT_NAME=$w[3];
          $BARCOD=$w[4];
          $PRODUCT_CODE=$w[5];
          $PRODUCT_DETAIL=$w[6];
          $db->query("INSERT INTO stoklar (PRICE_KDV, SALEABLE_STOCK, PRODUCT_ID, PRODUCT_NAME, BARCOD, PRODUCT_CODE, PRODUCT_DETAIL)
          values ('
$PRICE_KDV','$SALEABLE_STOCK','$PRODUCT_ID','$PRODUCT_NAME','$BARCOD','$PRODUCT_CODE','$PRODUCT_DETAIL')");
        }


        if ($db->transStatus() === false) {
            $db->transRollback();
        } else {
            $db->transCommit();
        



RE: CI4 Transaction not working on me - InsiteFX - 09-24-2021

You should not be using all capital letters for your variables, they are reserved for constants


RE: CI4 Transaction not working on me - kenjis - 09-24-2021

What error message do you get?

And you should not use htmlentities() and stripslashes() with SQL statements.
If you don't know escaping in SQL well,
see https://codeigniter4.github.io/CodeIgniter4/database/queries.html#escaping-queries