Guest User

fef

a guest
Feb 21st, 2018
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. <?php
  2.  
  3. class DBController {
  4. private $conn = "";
  5. private $host = "localhost";
  6. private $user = "root";
  7. private $password = "";
  8. private $database = "";
  9.  
  10. function __construct() {
  11. $conn = $this->connectDB();
  12. if(!empty($conn)) {
  13. $this->conn = $conn;
  14. }
  15. }
  16.  
  17. function connectDB() {
  18. $conn = mysqli_connect($this->host,$this->user,$this->password,$this->database);
  19. return $conn;
  20. }
  21.  
  22. function runSelectQuery($query) {
  23. $result = mysqli_query($this->conn,$query);
  24. while($row=@mysqli_fetch_assoc($result)) {
  25. $resultset[] = $row;
  26. }
  27. if(!empty($resultset))
  28. return $resultset;
  29. }
  30.  
  31. function executeInsert($query) {
  32. //echo $query;die;
  33. $result = mysqli_query($this->conn,$query);
  34. $insert_id = mysqli_insert_id($this->conn);
  35. return $insert_id;
  36.  
  37. }
  38. function executeUpdate($query) {
  39. $result = mysqli_query($this->conn,$query);
  40. return $result;
  41.  
  42. }
  43.  
  44. function executeQuery($sql) {
  45. $result = mysqli_query($this->conn,$sql);
  46. return $result;
  47.  
  48. }
  49.  
  50. function numRows($query) {
  51. $result = mysqli_query($this->conn,$query);
  52. $rowcount = mysqli_num_rows($result);
  53. return $rowcount;
  54. }
  55. }
  56. ?>
Add Comment
Please, Sign In to add comment