Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- define("TESTINPUT", '{"username":"Your db username","password":"Your db password","db":"test","ingredient":{"Ingredient":{"IngredientId":"68"},"Amount":20000}}');
- //$input = json_decode(file_get_contents('php://input'));
- $input = json_decode(TESTINPUT);
- $success = true;
- $db = new mysqli('localhost', $input->username, $input->password, $input->db);
- //Init
- $db->autocommit(false);
- $stmt = $db->prepare("INSERT INTO INGREDIENT_BATCHES (IngredientId, StockLevel) VALUES (?, ?)");
- $plab = $db->prepare("INSERT INTO PENDING_LABELS (Barcode) VALUES (?)");
- $ingredient = $input->ingredient;
- //Bind param
- $stmt->bind_param("ii", $ingredient->Ingredient->IngredientId, $ingredient->StockLevel);
- //Execute
- $stmt->execute();
- // This code works
- //$temp = $db->insert_id;
- //$plab->bind_param("i", $temp);
- // This code doesn't
- $plab->bind_param("i", $db->insert_id);
- $plab->execute();
- if ($plab->error != "") {
- $success = false;
- $errmsg = "Error executing query: " . $plab->error;
- }
- //Commit/Rollback
- if ($success) {
- echo "Able to commit";
- //$db->commit();
- } else {
- $db->rollback();
- echo $errmsg;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement