Guest User

Untitled

a guest
Dec 16th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. <?php
  2. class SQL {
  3. private static $link = null;
  4.  
  5. private $sql;
  6. private $result;
  7. private $affected_rows;
  8. private $insert_id;
  9.  
  10. public function __construct($sql) {
  11. $link = $this->connect();
  12. $this->sql = $sql;
  13. $this->result = $link->query($sql);
  14. $this->affected_rows = $link->affected_rows;
  15. $this->insert_id = $link->insert_id;
  16. }
  17.  
  18. public function affectedRows() {
  19. return $this->result ? $this->affected_rows : false;
  20. }
  21.  
  22. private static function connect() {
  23. if(!self::$link) {
  24. global $mysql_host, $mysql_user, $mysql_pass, $mysql_db;
  25. self::$link = new mysql($mysql_host, $mysql_user, $mysql_pass, $mysql_db);
  26. }
  27. return self::$link;
  28. }
  29.  
  30. public static function escape($string) {
  31. return self::connect()->real_escape_string($string);
  32. }
  33.  
  34. public function getInsertID() {
  35. return $this->insert_id;
  36. }
  37.  
  38. public function getResult() {
  39. return $this->result;
  40. }
  41.  
  42. public function getRow($field = null) {
  43. $value = false;
  44. if($this->result) {
  45. $value = $this->result->fetch_assoc();
  46.  
  47. if($value && $field) {
  48. $value = isset($value[$field]) ? $value[$field] : false;
  49. }
  50. }
  51. return $value;
  52. }
  53.  
  54. public function getRows($field = null) {
  55. $data = array();
  56.  
  57. while($row = $this->getRow($field)) {
  58. $data[] = $row;
  59. }
  60.  
  61. return $data;
  62. }
  63.  
  64. public function getSQL() {
  65. return $this->sql;
  66. }
  67.  
  68. public function numRows() {
  69. return $this->result ? $this->result->num_rows : false;
  70. }
  71. }
Add Comment
Please, Sign In to add comment