Guest User

Untitled

a guest
May 1st, 2018
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. <?php
  2.  
  3. // Simple MySQL class
  4. // Created by Bipshark
  5. // E-mail: faz@live.se
  6. // This comment should not be removed
  7.  
  8. class mysql
  9. {
  10. public $_host;
  11. public $_user;
  12. public $_pass;
  13. public $_db;
  14.  
  15. public $_result;
  16. public $_sql;
  17. public $_query;
  18. public $_link;
  19.  
  20. public function __construct($_host = '', $_user = '', $_pass = '', $_db = '')
  21. {
  22. return $this->connect($_host, $_user, $_pass, $_db);
  23. }
  24.  
  25. public function __desctruct()
  26. {
  27. if(isset($this->_query)) { mysql_free_result($this->_query); }
  28.  
  29. return mysql_close($this->_link);
  30. }
  31.  
  32. public function connect($_host, $_user, $_pass, $_db)
  33. {
  34. $this->_host = $_host;
  35. $this->_user = $_user;
  36. $this->_pass = $_pass;
  37. $this->_db = $_db;
  38.  
  39. $this->_link = mysql_connect($this->_host, $this->_user, $this->_pass) or die(mysql_error());
  40.  
  41. if($this->_db)
  42. {
  43. $this->select_database($this->_db) or die(mysql_error());
  44. }
  45.  
  46. return $this->_link;
  47. }
  48.  
  49. function select_database($_db)
  50. {
  51. $this->_db = $_db;
  52.  
  53. return mysql_select_db($_db) or die(mysql_error());
  54. }
  55.  
  56. public function query($_query)
  57. {
  58. $args = func_get_args();
  59. $this->_sql = $_query;
  60. array_shift($args);
  61.  
  62. if(count($args) > 0)
  63. {
  64. foreach($args as $key => $value)
  65. {
  66. $replace = ((is_float($value)) ? mysql_real_escape_string($value) : "'" . mysql_real_escape_string($value) . "'");
  67. $this->_sql = str_replace('%' . ++$key, $replace, $this->_sql);
  68. }
  69. }
  70.  
  71. $this->_query = mysql_query($this->_sql, $this->_link) or die(mysql_error());
  72.  
  73. return $this->_query;
  74. }
  75.  
  76. public function fetch($_query = '', $type = 'assoc')
  77. {
  78. $_query = ((empty($_query)) ? $this->_query : $_query);
  79. $this->_result = ((strtolower($type) == 'assoc') ? mysql_fetch_assoc($_query) : mysql_fetch_row($_query));
  80.  
  81. return $this->_result;
  82. }
  83.  
  84. public function num_rows($_query = '')
  85. {
  86. $_query = ((empty($_query)) ? $this->_query : $_query);
  87.  
  88. return mysql_num_rows($_query);
  89. }
  90. }
  91.  
  92. ?>
Add Comment
Please, Sign In to add comment