Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.48 KB | None | 0 0
  1. <?php
  2. header('Content-type: text/html; charset=utf-8');
  3. // header('Content-type: text/plain; charset=utf-8');
  4.  
  5. ini_set("display_errors", 1);
  6. ini_set("track_errors", 1);
  7. ini_set("html_errors", 1);
  8. ini_set("realpath_cache_size", '5M');
  9. ini_set('max_execution_time', 9999999900000);
  10. error_reporting(E_ALL);
  11.  
  12. define('_USER_', 'username');
  13. define('_PASSWD_', 'password');
  14. define('_DB_', 'database');
  15.  
  16. global $mysqli;
  17. $mysqli = new mysqli('localhost', _USER_, _PASSWD_, _DB_);
  18.  
  19. $timeStart = microtime_float();
  20.  
  21. $mysqli->query('SELECT * FROM schema.table');
  22.  
  23. $timeEnd = microtime_float();
  24.  
  25. $time = $timeEnd - $timeStart;
  26. echo PHP_EOL . "Execution time : $time";
  27. echo PHP_EOL . '--- END ---';
  28. die();
  29.  
  30.  
  31.  
  32.  
  33. /**
  34. * Execute an array of sql for updating base
  35. * @return nothing
  36. */
  37. function executeArray($allSql)
  38. {
  39. global $mysqli;
  40.  
  41. if ($mysqli->connect_errno) {
  42. echo "<br>----------------------------";
  43. echo "<br>Sorry, first try connect_errno.";
  44. }
  45.  
  46. foreach ($allSql as $key => $sql) {
  47. if (!$result = $mysqli->query($sql)) {
  48. echo "<br>----------------------------";
  49. echo " <br>Sorry, here the problem:";
  50. echo " <br>Query: " . $sql ;
  51. echo " <br>Errno: " . $mysqli->errno ;
  52. echo " <br>Error: " . $mysqli->error ;
  53. exit;
  54. }
  55. }
  56.  
  57. return true;
  58. }
  59.  
  60. /**
  61. * Execute an SQL, and return an result array
  62. * @return array of int
  63. */
  64. function executeS($sql)
  65. {
  66. global $mysqli;
  67.  
  68. if ($mysqli->connect_errno) {
  69. echo "<br>----------------------------";
  70. echo "<br>Sorry, first try connect_errno.";
  71. }
  72.  
  73. if (!$result = $mysqli->query($sql)) {
  74. echo "<br>----------------------------";
  75. echo " <br>Sorry, here the problem:";
  76. echo " <br>Query: " . $sql ;
  77. echo " <br>Errno: " . $mysqli->errno ;
  78. echo " <br>Error: " . $mysqli->error ;
  79. exit;
  80. }
  81.  
  82. $rows = array();
  83.  
  84. while ($row = $result->fetch_assoc()) {
  85. array_push($rows, $row);
  86. }
  87.  
  88. return $rows;
  89. }
  90.  
  91.  
  92. /**
  93. * Execute only one sql for the setting of base eg ALTER ...
  94. * @return nothing
  95. */
  96. function executeOne($sql)
  97. {
  98. global $mysqli;
  99.  
  100. if ($mysqli->connect_errno) {
  101. echo "<br>----------------------------";
  102. echo "<br>Sorry, first try connect_errno.";
  103. }
  104.  
  105. if (!$result = $mysqli->query($sql)) {
  106. echo "<br>----------------------------";
  107. echo " <br>Sorry, here the problem:";
  108. echo " <br>Query: " . $sql ;
  109. echo " <br>Errno: " . $mysqli->errno ;
  110. echo " <br>Error: " . $mysqli->error ;
  111. exit;
  112. }
  113.  
  114. return true;
  115. ;
  116. }
  117.  
  118. function microtime_float()
  119. {
  120. list($usec, $sec) = explode(" ", microtime());
  121. return ((float)$usec + (float)$sec);
  122. }
  123.  
  124.  
  125. /**
  126. * Execute an SQL, and return an result array
  127. * @return array of int
  128. */
  129. function getValue($sql)
  130. {
  131. $result = connectAndExecuteSQL($sql);
  132.  
  133. $rows = array();
  134.  
  135. while ($row = $result->fetch_assoc()) {
  136. array_push($rows, $row);
  137. }
  138.  
  139. return $rows;
  140. }
  141.  
  142.  
  143. function connectAndExecuteSQL($sql, $is_array = null)
  144. {
  145. global $mysqli;
  146.  
  147. if ($mysqli->connect_errno) {
  148. echo "<br>----------------------------";
  149. echo "<br>Sorry, first try connect_errno.";
  150. }
  151.  
  152. if (!$result = $mysqli->query($sql)) {
  153. echo "<br>----------------------------";
  154. echo " <br>Sorry, here the problem:";
  155. echo " <br>Query: " . $sql ;
  156. echo " <br>Errno: " . $mysqli->errno ;
  157. echo " <br>Error: " . $mysqli->error ;
  158. exit;
  159. }
  160.  
  161. return $mysqli;
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement