Guest User

Untitled

a guest
May 7th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. class MyPDO extends PDO
  2. {
  3. protected $_table_prefix;
  4. protected $_table_suffix;
  5.  
  6. public function __construct($dsn, $user = null, $password = null, $driver_options = array(), $prefix = null, $suffix = null)
  7. {
  8. $this->_table_prefix = $prefix;
  9. $this_table_suffix = $suffix;
  10. parent::__construct($dsn, $user, $password, $driver_options);
  11. }
  12.  
  13. public function exec($statement)
  14. {
  15. $statement = $this->_tablePrefixSuffix($statement);
  16. return parent::exec($statement);
  17. }
  18.  
  19. public function prepare($statement, $driver_options = array())
  20. {
  21. $statement = $this->_tablePrefixSuffix($statement);
  22. return parent::prepare($statement, $driver_options);
  23. }
  24.  
  25. public function query($statement)
  26. {
  27. $statement = $this->_tablePrefixSuffix($statement);
  28. $args = func_get_args();
  29.  
  30. if (count($args) > 1) {
  31. return call_user_func_array(array($this, 'parent::query'), $args);
  32. } else {
  33. return parent::query($statement);
  34. }
  35. }
  36.  
  37. protected function _tablePrefixSuffix($statement)
  38. {
  39. return sprintf($statement, $this->_table_prefix, $this_table_suffix);
  40. }
  41. }
Add Comment
Please, Sign In to add comment