Advertisement
Guest User

Untitled

a guest
May 25th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. <?php
  2. namespace OdooOfficeHelper;
  3.  
  4. use MagentoFrameworkAppResourceConnection;
  5. /**
  6. *
  7. */
  8. class DbConnection
  9. {
  10. /**
  11. * Define common connection
  12. * @var unknown
  13. */
  14. protected $_resource;
  15. protected $_dbConnection;
  16.  
  17. protected function __construct(
  18. ResourceConnection $resource,
  19. )
  20. {
  21. # code...
  22. // Set common connection
  23. $this->_resource = $resource;
  24. $this->_dbConnection = $this->_resource->getConnection();
  25. }
  26.  
  27. public function Trans(){
  28. try{
  29. // Start transaction
  30. $this->_dbConnection->beginTransaction();
  31.  
  32. //........
  33.  
  34. // Commit transaction
  35. $this->_dbConnection->commit();
  36. } catch (Exception $e) {
  37. // Rollback transaction
  38. $this->_dbConnection->rollBack();
  39. }
  40. }
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement