Advertisement
Guest User

Untitled

a guest
Jan 4th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.15 KB | None | 0 0
  1. <?php
  2. /**
  3. * PHP Document Object plus
  4. *
  5. * PHP Document Object plus is library with functionality of PDO, entirely written
  6. * in PHP, so that developer can easily extend it's classes with specific functionality,
  7. * such as providing database usage statistics implemented in v1.0b
  8. *
  9. * @author Peter Pokojny
  10. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  11. */
  12. class PDOp {
  13. protected $PDO;
  14. public $numExecutes;
  15. public $numStatements;
  16. public function __construct($dsn, $user=NULL, $pass=NULL, $driver_options=NULL) {
  17. $this->PDO = new PDO($dsn, $user, $pass, $driver_options);
  18. $this->numExecutes = 0;
  19. $this->numStatements = 0;
  20. }
  21. public function __call($func, $args) {
  22. return call_user_func_array(array(&$this->PDO, $func), $args);
  23. }
  24. public function prepare() {
  25. $this->numStatements++;
  26.  
  27. $args = func_get_args();
  28. $PDOS = call_user_func_array(array(&$this->PDO, 'prepare'), $args);
  29.  
  30. return new PDOpStatement($this, $PDOS);
  31. }
  32. public function query() {
  33. $this->numExecutes++;
  34. $this->numStatements++;
  35.  
  36. $args = func_get_args();
  37. $PDOS = call_user_func_array(array(&$this->PDO, 'query'), $args);
  38.  
  39. return new PDOpStatement($this, $PDOS);
  40. }
  41. public function exec() {
  42. $this->numExecutes++;
  43.  
  44. $args = func_get_args();
  45. return call_user_func_array(array(&$this->PDO, 'exec'), $args);
  46. }
  47. }
  48. class PDOpStatement implements IteratorAggregate {
  49. protected $PDOS;
  50. protected $PDOp;
  51. public function __construct($PDOp, $PDOS) {
  52. $this->PDOp = $PDOp;
  53. $this->PDOS = $PDOS;
  54. }
  55. public function __call($func, $args) {
  56. return call_user_func_array(array(&$this->PDOS, $func), $args);
  57. }
  58. public function bindColumn($column, &$param, $type=NULL) {
  59. if ($type === NULL)
  60. $this->PDOS->bindColumn($column, $param);
  61. else
  62. $this->PDOS->bindColumn($column, $param, $type);
  63. }
  64. public function bindParam($column, &$param, $type=NULL) {
  65. if ($type === NULL)
  66. $this->PDOS->bindParam($column, $param);
  67. else
  68. $this->PDOS->bindParam($column, $param, $type);
  69. }
  70. public function execute() {
  71. $this->PDOp->numExecutes++;
  72. $args = func_get_args();
  73. return call_user_func_array(array(&$this->PDOS, 'execute'), $args);
  74. }
  75. public function __get($property) {
  76. return $this->PDOS->$property;
  77. }
  78. public function getIterator() {
  79. return $this->PDOS;
  80. }
  81. }
  82. ?>
  83.  
  84. Classes have properties with original PDO and PDOStatement objects, which are providing the functionality to PDOp and PDOpStatement.
  85. From outside, PDOp and PDOpStatement look like PDO and PDOStatement, but also are providing wanted info.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement