Guest User

Untitled

a guest
May 3rd, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. <?php
  2. /* SQL class - @author ThisIsAreku */
  3. class SQL {
  4. var $_VERSION = "1.2";
  5.  
  6. var $host;
  7. var $user;
  8. var $pass;
  9. var $database;
  10.  
  11. var $con;
  12.  
  13. function SQL($host, $user, $pass, $database) {
  14. $this->host = $host;
  15. $this->pass = $pass;
  16. $this->user = $user;
  17. $this->database = $database;
  18. $this->__connect();
  19. }
  20. private function __connect() {
  21. $this->con = mysql_connect($this->host, $this->user, $this->pass);
  22. mysql_select_db($this->database, $this->con);
  23. mysql_query("SET NAMES 'utf8'", $this->con);
  24. }
  25. private function __compile($query) {
  26. if ($query === false || $query === true) return $query;
  27. $out = array();
  28. $id = 0;
  29. while($row = mysql_fetch_assoc($query)) {
  30. $out[$id] = $row;
  31. $id += 1;
  32. }
  33. return $out;
  34. }
  35. private function __escape($d) {
  36. if(is_array($d))
  37. foreach($d as $k => $v)
  38. $d[$k] = $this->__escape($v);
  39. elseif(is_string($d))
  40. $d = mysql_real_escape_string($d, $this->con);
  41. return $d;
  42. }
  43.  
  44.  
  45.  
  46. public function escape($data) {
  47. return $this->__escape($data);
  48. }
  49.  
  50. public function last_error() {
  51. return mysql_error($this->con);
  52. }
  53.  
  54. public function showTable($table, $columns = null, $more = null){
  55. $sql = "SELECT ";
  56. if(!$columns == null) {
  57. foreach($columns as $c) {
  58. $sql .= "`" . $c . "`, ";
  59. }
  60. $sql = substr($sql, 0, (strlen($sql) - 2));
  61. }else{
  62. $sql .= "*";
  63. }
  64. $sql .= " FROM `".$table."`";
  65. if(!$more == null) $sql .= ' '.$more;
  66. $query = mysql_query($sql, $this->con);
  67. return $this->__compile($query);
  68. }
  69.  
  70. public function getColumn($result_array, $row) {
  71. $r = array();
  72. for($i=0; $i < count($result_array); $i++) {
  73. $r[$i] = $result_array[$i][$row];
  74. }
  75. return $r;
  76. }
  77.  
  78. public function execute($sql){
  79. $query = mysql_query($sql, $this->con);
  80. return $this->__compile($query);
  81. }
  82. }
Add Comment
Please, Sign In to add comment