Connect.class.php 1023 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. *
  4. */
  5. class Connect
  6. {
  7. private static $transaction;
  8. /**
  9. * @return mixed
  10. */
  11. public static function beginTransaction()
  12. {
  13. self::$transaction = $GLOBALS['db']->StartTrans();
  14. }
  15. public static function rollback()
  16. {
  17. $GLOBALS['db']->Rollback(self::$transaction);
  18. }
  19. public static function commit()
  20. {
  21. $GLOBALS['db']->Commit(self::$transaction);
  22. }
  23. public static function inTransaction()
  24. {
  25. return $GLOBALS['db']->InTransaction();
  26. }
  27. public static function lastInsertId()
  28. {
  29. return $GLOBALS['db']->insert_id();
  30. }
  31. public static function exec($sql)
  32. {
  33. return $GLOBALS['db']->query($sql) ? $GLOBALS['db']->affected_rows() : false;
  34. }
  35. /**
  36. * @param $sql
  37. * @param bool $is_all
  38. * @return mixed
  39. */
  40. public static function query($sql, $is_all = true)
  41. {
  42. return $is_all ? $GLOBALS['db']->getAll($sql, 1, 1) : $GLOBALS['db']->getRow($sql, 1, 1);
  43. }
  44. }