Guest User

Untitled

a guest
May 27th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.20 KB | None | 0 0
  1. <?php
  2.  
  3. if (class_exists('mysqli')) {
  4. return;
  5. }
  6.  
  7. class mysqli_result_facade {
  8. protected $result;
  9. protected $fields = array();
  10.  
  11. public function __construct($result) {
  12. $this->result = $result;
  13. }
  14.  
  15. public function fetch_assoc() {
  16. return mysql_fetch_assoc($this->result);
  17. }
  18.  
  19. public function fetch_fields() {
  20. if (count($this->fields)) {
  21. return $this->fields;
  22. }
  23.  
  24. $i = 0;
  25. while ($i < mysql_num_fields($result)) {
  26. $this->fields[]= mysql_fetch_field($result, $i);
  27. }
  28. return $this->fields;
  29. }
  30.  
  31. public function free() {
  32. mysql_free_result($this->result);
  33. }
  34.  
  35. public function __get($name) {
  36. if ($name == 'num_rows') {
  37. return $this->num_rows();
  38. }
  39. }
  40.  
  41. private function num_rows() {
  42. return mysql_num_rows($this->result);
  43. }
  44. }
  45.  
  46. class mysqli {
  47. protected $connect;
  48. protected $results;
  49.  
  50. protected function freeAllResults() {
  51. foreach ($this->results as $r) {
  52. $r->free();
  53. }
  54. $this->results = array();
  55. }
  56.  
  57. protected function doQuery($stmt, $preserve = false) {
  58. if (!$preserve) {
  59. $this->freeAllResults();
  60. }
  61.  
  62. error_log($stmt);
  63.  
  64. $result = mysql_query($stmt, $this->connect);
  65.  
  66. error_log(mysql_error($this->connect));
  67.  
  68. if ($result !== TRUE && $result !== FALSE) {
  69. $result = new mysqli_result_facade($result);
  70. }
  71.  
  72. $this->results[] = $result;
  73. }
  74.  
  75. public function __construct($host = "localhost", $user = "root", $pass = "", $port = 3306) {
  76. $this->connect = mysql_connect($host, $user, $pass, $port);
  77. $this->results = array();
  78. }
  79.  
  80. public function select_db($db) {
  81. return mysql_select_db($db, $this->connect);
  82. }
  83.  
  84. public function multi_query($statements) {
  85. // transform escaped ; to token
  86. $statements = explode(';', str_replace('\;', '__ESCAPED_SEMI__', $statements));
  87. foreach ($statements as $stmt) {
  88. $this->doQuery(str_replace('__ESCAPED_SEMI__', '\;', $stmt), true);
  89. }
  90. return true;
  91. }
  92.  
  93. public function query($statement) {
  94. $this->doQuery($statement);
  95. return (isset($this->results[0])) ? $this->results[0] : FALSE;
  96. }
  97.  
  98. public function store_result() {
  99. return $this->results[0];
  100. }
  101.  
  102. public function next_result() {
  103. array_shift($this->results);
  104. }
  105.  
  106. public function close() {
  107. mysql_close($this->connect);
  108. }
  109.  
  110. private function affected_rows() {
  111. return mysql_affected_rows($this->connect);
  112. }
  113.  
  114. private function warning_count() {
  115. $result = $this->query('SHOW COUNT(*) WARNINGS');
  116. $row = $result->fetch_assoc();
  117. return $row['count'];
  118. }
  119.  
  120. public function __get($name) {
  121. if ($name == 'affected_rows') {
  122. return $this->affected_rows();
  123. }
  124. if ($name == 'warning_count') {
  125. return $this->warning_count();
  126. }
  127. }
  128.  
  129. }
  130.  
  131.  
  132. function mysqli_connect_errno() {
  133.  
  134. }
  135.  
  136. function mysqli_connect_error() {
  137.  
  138. }
Add Comment
Please, Sign In to add comment