Guest User

Untitled

a guest
Jan 23rd, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. <?php
  2. class DB {
  3. public $link;
  4.  
  5. public function __construct($server="localhost",$user="root",$pass="",$database="speteam") {
  6. $this->link = new mysqli($server,$user,$pass,$database);
  7.  
  8. if ($this->link->connect_error) {
  9. trigger_error('Error: Could not make a database link (' . $this->link->connect_errno . ') ' . $this->link->connect_error);
  10. exit();
  11. }
  12.  
  13. $this->link->set_charset("utf8mb4");
  14. $this->link->query("SET SQL_MODE = ''");
  15. }
  16.  
  17. public function query($sql) {
  18. $query = $this->link->query($sql);
  19.  
  20. if (!$this->link->errno) {
  21. if ($query instanceof mysqli_result) {
  22. $data = array();
  23.  
  24. while ($row = $query->fetch_assoc()) {
  25. $data[] = $row;
  26. }
  27.  
  28. $result = new stdClass();
  29. $result->num_rows = $query->num_rows;
  30. $result->row = isset($data[0]) ? $data[0] : arra
  31. $result->rows = $data;
  32.  
  33. $query->close();
  34.  
  35. return $result;
  36. } else {
  37. return true;
  38. }
  39. } else {
  40. trigger_error('Error: ' . $this->link->error . '<br />Error No: ' . $this->link->errno . '<br />' . $sql);
  41. }
  42. }
  43.  
  44. public function escape($value) {
  45. return $this->link->real_escape_string($value);
  46. }
  47.  
  48. public function countAffected() {
  49. return $this->link->affected_rows;
  50. }
  51.  
  52. public function getLastId() {
  53. return $this->link->insert_id;
  54. }
  55.  
  56. public function __destruct() {
  57. $this->link->close();
  58. }
  59. }
  60. ?>
Add Comment
Please, Sign In to add comment