Guest User

Untitled

a guest
May 8th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. <?php
  2.  
  3. define("OBJECT", "object");
  4.  
  5. define("ASSOC", "assoc");
  6.  
  7. define("ARRAY", "array");
  8.  
  9.  
  10.  
  11. class MySQL
  12.  
  13. {
  14.  
  15. private $host, $username, $password, $database, $statement;
  16.  
  17. public $final;
  18.  
  19.  
  20.  
  21. public static function __construct($host, $username, $password, $database)
  22.  
  23. {
  24.  
  25. $this->username = $username;
  26.  
  27. $this->password = $password;
  28.  
  29. $this->host = $host;
  30.  
  31. $this->database = $database;
  32.  
  33.  
  34.  
  35. $SQLServer = mysql_connect($this->host, $this->username, $this->password);
  36.  
  37. mysql_select_db($this->database, $SQLServer);
  38.  
  39. }
  40.  
  41.  
  42.  
  43. public static function query($query)
  44.  
  45. {
  46.  
  47. return mysql_query($query);
  48.  
  49. }
  50.  
  51.  
  52.  
  53. public static function fetch($resultQuery, $type = "object")
  54.  
  55. {
  56.  
  57. if(isset($type))
  58.  
  59. {
  60.  
  61. switch($type)
  62.  
  63. {
  64.  
  65. case "object":
  66.  
  67. return mysql_fetch_object($resultQuery);
  68.  
  69. break;
  70.  
  71. case "array":
  72.  
  73. return mysql_fetch_array($resultQuery);
  74.  
  75. break;
  76.  
  77. case "assoc":
  78.  
  79. return mysql_fetch_assoc($resultQuery);
  80.  
  81. break;
  82.  
  83. default:
  84.  
  85. return mysql_fetch_object($resultQuery);
  86.  
  87. }
  88.  
  89. }
  90.  
  91. else
  92.  
  93. {
  94.  
  95. return mysql_fetch_object($resultQuery);
  96.  
  97. }
  98.  
  99. }
  100.  
  101.  
  102.  
  103. public static function counts($resultCount)
  104.  
  105. {
  106.  
  107. return mysql_num_rows($resultCount);
  108.  
  109. }
  110.  
  111.  
  112.  
  113. public static function error()
  114.  
  115. {
  116.  
  117. return mysql_error();
  118.  
  119. }
  120.  
  121.  
  122.  
  123. public static function errno()
  124.  
  125. {
  126.  
  127. if(mysql_errno())
  128.  
  129. {
  130.  
  131. return true;
  132.  
  133. }
  134.  
  135. else
  136.  
  137. {
  138.  
  139. return false;
  140.  
  141. }
  142.  
  143. }
  144.  
  145.  
  146.  
  147. public static function prepare($statement)
  148.  
  149. {
  150.  
  151. $this->statement = $statement;
  152.  
  153. }
  154.  
  155.  
  156.  
  157. public static function bind($inQuery, $value)
  158.  
  159. {
  160.  
  161. if(is_array($inQuery) && is_array($value))
  162.  
  163. {
  164.  
  165. if(count($inQuery) == count($value))
  166.  
  167. {
  168.  
  169. $finalQuery = array();
  170.  
  171. for($x = 0; $x <= count($inQuery) - 1; $x++)
  172.  
  173. {
  174.  
  175. $finalQuery[$x] = str_replace($inQuery[$x], $value[$x], $this->statement);
  176.  
  177. }
  178.  
  179. }
  180.  
  181. else
  182.  
  183. {
  184.  
  185. throw new Exception("Invalid array argument count for MySQL::bind.");
  186.  
  187. }
  188.  
  189. }
  190.  
  191. else
  192.  
  193. {
  194.  
  195. $this->final = str_replace($inQuery, $value, $this->statement);
  196.  
  197. }
  198.  
  199.  
  200.  
  201. if(isset($finalQuery))
  202.  
  203. {
  204.  
  205. $this->final = end($finalQuery);
  206.  
  207. }
  208.  
  209.  
  210.  
  211. unset($this->statement);
  212.  
  213. }
  214.  
  215.  
  216.  
  217. public static function execute()
  218.  
  219. {
  220.  
  221. return $this->query($this->final);
  222.  
  223. }
  224.  
  225.  
  226.  
  227. }
Add Comment
Please, Sign In to add comment