Advertisement
Guest User

Untitled

a guest
Feb 9th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. $this->db->beginTransaction();
  2. try
  3. {
  4. $this->db->query("SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED");
  5.  
  6. $sth = $this->db->prepare("INSERT INTO books(title, categoryID, publisherID, date, description, price, image)
  7. VALUES (:title, :categoryID, :publisherID, :date, :description, :price, :image)");
  8. $sth->execute(array(
  9. ':title' => $title,
  10. ':categoryID' => $categoryID,
  11. ':publisherID' => $publisherID,
  12. ':date' => $date,
  13. ':description' => $description,
  14. ':price' => $price,
  15. ':image' => $image_path
  16. ));
  17.  
  18. $bookID = $this->db->prepare("SELECT bookID FROM books WHERE title = :title");
  19. $bookID->execute(array(
  20. ':title' => $title,
  21. ));
  22. $row=$bookID->fetch();
  23. $book = intval($row[0]);
  24.  
  25. $sth = $this->db->prepare("INSERT INTO books_authors(bookID,authorID)
  26. VALUES (:bookID, :authorID)");
  27. $sth->execute(array(
  28. ':bookID' => $book,
  29. ':authorID' => $authorID
  30. ));
  31.  
  32. $this->db->commit();
  33. }
  34. catch (PDOException $e)
  35. {
  36. $this->db->rollback();
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement