Advertisement
Nordicus

mysqli bug

Jan 28th, 2016
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.16 KB | None | 0 0
  1. <?php
  2.     define("TESTINPUT", '{"username":"Your db username","password":"Your db password","db":"test","ingredient":{"Ingredient":{"IngredientId":"68"},"Amount":20000}}');
  3.    
  4.     //$input = json_decode(file_get_contents('php://input'));
  5.     $input = json_decode(TESTINPUT);
  6.    
  7.     $success = true;
  8.     $db = new mysqli('localhost', $input->username, $input->password, $input->db);
  9.    
  10.     //Init
  11.     $db->autocommit(false);
  12.     $stmt = $db->prepare("INSERT INTO INGREDIENT_BATCHES (IngredientId, StockLevel) VALUES (?, ?)");
  13.     $plab = $db->prepare("INSERT INTO PENDING_LABELS (Barcode) VALUES (?)");
  14.     $ingredient = $input->ingredient;
  15.    
  16.     //Bind param
  17.     $stmt->bind_param("ii", $ingredient->Ingredient->IngredientId, $ingredient->StockLevel);
  18.    
  19.     //Execute
  20.     $stmt->execute();
  21.    
  22.     // This code works
  23.     //$temp = $db->insert_id;
  24.     //$plab->bind_param("i", $temp);
  25.    
  26.     // This code doesn't
  27.     $plab->bind_param("i", $db->insert_id);
  28.     $plab->execute();
  29.     if ($plab->error != "") {
  30.         $success = false;
  31.         $errmsg = "Error executing query: " . $plab->error;
  32.     }
  33.    
  34.     //Commit/Rollback
  35.     if ($success) {
  36.         echo "Able to commit";
  37.         //$db->commit();
  38.     } else {
  39.         $db->rollback();
  40.         echo $errmsg;
  41.     }
  42. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement