Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4. * To change this license header, choose License Headers in Project Properties.
  5. * To change this template file, choose Tools | Templates
  6. * and open the template in the editor.
  7. */
  8.  
  9. /**
  10. * Description of DatabseClass
  11. *
  12. * @author Admin
  13. */
  14. class DatabseClass {
  15. private $db_name='swe_project';
  16. private $host_name="localhost";
  17. private $username='root';
  18. private $password='';
  19. private $db_connnection;
  20.  
  21. public function __construct() {
  22. $this->db_connnection=$this->db_connect();
  23. }
  24.  
  25. private function db_connect(){
  26. $connection= mysqli_connect($this->host_name, $this->username, $this->password, $this->db_name);
  27. if($connection){
  28. return $connection;
  29. }
  30. else{
  31. die("Databse Connection Error");
  32. }
  33.  
  34.  
  35.  
  36. }
  37. public function database_query($query){
  38. $result= mysqli_query($this->db_connnection, $query);
  39. return $result;
  40. }
  41. public function database_result_assoc($result){
  42. $data=array();
  43.  
  44. $counter=0;
  45. while ($row=mysqli_fetch_assoc($result)){
  46. $counter=$counter+1;
  47. $key='user'.$counter;
  48. $data[$key]=$row;
  49. }
  50.  
  51. return $data;
  52. }
  53.  
  54. public function row_count($result){
  55. return mysqli_num_rows($result);
  56. }
  57.  
  58. public function db_close(){
  59. if(!mysqli_close($this->db_connnection)){
  60. die("DB Connection Closing Failed !");
  61. }
  62. }
  63.  
  64.  
  65.  
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement