Guest User

Untitled

a guest
Jan 14th, 2018
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. <?php
  2.  
  3. Class Database {
  4.  
  5. public $host = DB_HOST;
  6. public $user = DB_USER;
  7. public $pass = DB_PASS;
  8. public $dbname = DB_NAME;
  9. public $link;
  10. public $error;
  11.  
  12. public function __construct() {
  13. $this->connectDB();
  14.  
  15. /* You also can use here. Adding additional for fixing bangla Font Issue
  16. $this->link->query("SET NAMES utf8");
  17. $this->link->query("SET CHARACTER SET utf8");
  18. $this->link->set_charset('utf8');
  19. $this->link->set_charset('utf-8');
  20. //End of Addintional issue by Saiful Islam */
  21. }
  22.  
  23. /**
  24. * Connecting Database with mysql
  25. *
  26. * @author Saiful Islam<codersaiful@gmail.com>
  27. * @return Object
  28. */
  29. private function connectDB() {
  30. $this->link = new mysqli($this->host, $this->user, $this->pass, $this->dbname);
  31.  
  32. //Adding additional for fixing bangla Font Issue
  33. $this->link->query("SET NAMES utf8");
  34. $this->link->query("SET CHARACTER SET utf8");
  35. $this->link->set_charset('utf8');
  36. $this->link->set_charset('utf-8');
  37. //End of Addintional issue by Saiful Islam
  38.  
  39. if (!$this->link) {
  40. $this->error = "Connection fail" . $this->link->connect_error;
  41. return false;
  42. }
  43. }
  44.  
  45. // Select or Read data
  46.  
  47. public function select($query) {
  48. $result = $this->link->query($query) or die($this->link->error . __LINE__);
  49. if ($result->num_rows > 0) {
  50. return $result;
  51. } else {
  52. return false;
  53. }
  54. }
  55.  
  56. // Insert data
  57. public function insert($query) {
  58. $insert_row = $this->link->query($query) or die($this->link->error . __LINE__);
  59. if ($insert_row) {
  60. header("Location: index.php?msg=" . urlencode('Data Inserted successfully.'));
  61. exit();
  62. } else {
  63. die("Error :(" . $this->link->errno . ")" . $this->link->error);
  64. }
  65. }
  66.  
  67. // Update data
  68. public function update($query) {
  69. $update_row = $this->link->query($query) or die($this->link->error . __LINE__);
  70. if ($update_row) {
  71. header("Location: index.php?msg=" . urlencode('Data Updated successfully.'));
  72. exit();
  73. } else {
  74. die("Error :(" . $this->link->errno . ")" . $this->link->error);
  75. }
  76. }
  77.  
  78. // Delete data
  79. public function delete($query) {
  80. $delete_row = $this->link->query($query) or die($this->link->error . __LINE__);
  81. if ($delete_row) {
  82. header("Location: index.php?msg=" . urlencode('Data Deleted successfully.'));
  83. exit();
  84. } else {
  85. die("Error :(" . $this->link->errno . ")" . $this->link->error);
  86. }
  87. }
  88.  
  89. }
Add Comment
Please, Sign In to add comment