Advertisement
denik-od

PHP MySQL Transaction wrong example

Aug 8th, 2018
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.42 KB | None | 0 0
  1. <?php
  2.     $DB->query("SET AUTOCOMMIT=0");
  3.     $DB->query("START TRANSACTION");
  4.     // Check of exists
  5.     $q = $DB->query("SELECT * FROM `test_overload` WHERE `code`='{$code}'");
  6.     if( $q->num_rows == 0 )
  7.     {
  8.         $DB->query($DB->insert_string('test_overload', $data));
  9.         $count_insert++;
  10.     }
  11.     else
  12.     {
  13.         $DB->query($DB->update_string('test_overload', $data, array('id'=>$q->row['id'])));
  14.         $count_update++;
  15.     }
  16.     $DB->query("COMMIT");
  17. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement