Advertisement
Guest User

fds

a guest
Nov 21st, 2016
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. <?php
  2.  
  3. class DatabaseController {
  4.  
  5.  
  6. public $handle;
  7.  
  8. public function getHandler() {
  9. return $this->handle;
  10. }
  11.  
  12. public function connectToDatabase($address, $username, $password, $databaseName) {
  13.  
  14. $this->handle = mysqli_connect($address, $username, $password, $databaseName);
  15. if(!$this->handle) {
  16. die("I can't connect to database. Error: " . mysqli_connect_error());
  17. return false;
  18. } else
  19. return true;
  20.  
  21. }
  22.  
  23. public function disconnectFromDatabase($handle) {
  24. mysqli_close($handle);
  25. }
  26.  
  27. public function signIn($handle, $username, $password) {
  28. $stmt = $handle->prepare("SELECT username, password FROM user WHERE username = ? && password = ?");
  29. $stmt->bind_param('ss', $username, $password);
  30. $stmt->execute();
  31. $result = $stmt->get_result();
  32. /* if ($data = $result->fetch_assoc()) {
  33. return $data;
  34. } else {
  35. return false;
  36. }*/
  37. $data = $result->fetch_assoc();
  38. return $data;
  39.  
  40. }
  41.  
  42. public function register($handle, $username, $password) {
  43.  
  44. $stmt = $handle->prepare("INSERT INTO user (username, password) VALUES(?, ?)");
  45. $stmt->bind_param("ss", $username, $password);
  46. $stmt->execute();
  47.  
  48. if($handle->affected_rows > 0) {
  49. return true;
  50. } else {
  51. return false;
  52. }
  53.  
  54. }
  55.  
  56. public function addVideo($handle, $user, $videoPath, $videoThumbnail, $videoExtension, $videoResolution, $videoTitle, $videoDescription) {
  57. $null = NULL;
  58. $stmt = $handle->prepare("INSERT INTO video (user, videoPath, videoThumbnail, videoExtension, videoResolution, videoTitle, videoDescription) VALUES (?, ?, ?, ?, ?, ?, ?)");
  59. $stmt->bind_param("ssbssss", $user, $videoPath, $null, $videoExtension, $videoResolution, $videoTitle, $videoDescription);
  60. $stmt->send_long_data(2, $videoThumbnail);
  61. $stmt->execute();
  62. if($handle->affected_rows > 0)
  63. return true;
  64. else
  65. return false;
  66.  
  67. }
  68.  
  69. public function getUserVideos($handle, $username) {
  70. $stmt = $handle->prepare("SELECT videoPath, videoThumbnail, videoExtension, videoResolution, videoTitle, videoDescription FROM video WHERE user = ?");
  71. $stmt->bind_param('s', $username);
  72. $stmt->execute();
  73.  
  74. $result = $stmt->get_result();
  75.  
  76. if($data = $result->fetch_all(MYSQLI_ASSOC)) {
  77. return $data;
  78. } else {
  79. return false;
  80. }
  81. }
  82.  
  83. public function getAllVideos($handle) {
  84.  
  85. $stmt = $handle->prepare("SELECT videoPath, videoThumbnail, videoExtension, videoResolution, videoTitle, videoDescription FROM video");
  86. $stmt->execute();
  87.  
  88. $result = $stmt->get_result();
  89.  
  90. if($data = $result->fetch_all(MYSQLI_ASSOC)) {
  91. return $data;
  92. } else {
  93. return false;
  94. }
  95.  
  96. }
  97.  
  98. }
  99.  
  100. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement