Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. <?php
  2.  
  3. class MySqlDrive
  4. {
  5. private $host = 'localhost';
  6. private $user = 'root';
  7. private $password = '';
  8. private $db = 'codeigniter_crud';
  9.  
  10. private $db_handle;
  11.  
  12. public function __construct()
  13. {
  14. $this->db_handle = mysqli_connect($this->host, $this->user, $this->password, $this->db);
  15.  
  16. if(!$this->db_handle) die("Unable to connect to mysql: " . mysqli_error($this->db_handle));
  17.  
  18. if(!mysqli_select_db($this->db_handle, $this->db)) die ("Unable to connect to database: " . mysqli_error($this->db_handle));
  19. }
  20.  
  21. public function db_connect()
  22. {
  23. return $this->db_handle;
  24. }
  25.  
  26. public function excute_query($query)
  27. {
  28. $result = mysqli_query($this->db_handle, $query);
  29.  
  30. return !$result ? FALSE : TRUE;
  31.  
  32. }
  33.  
  34. public function insert($query)
  35. {
  36. return $this->excute_query($query);
  37. }
  38.  
  39. public function read($query)
  40. {
  41. $result = mysqli_query($this->db_handle, $query);
  42. $row = mysqli_num_rows($result);
  43.  
  44. $data = array();
  45.  
  46. if($row){
  47. while ($row = mysqli_fetch_assoc($result))
  48. {
  49. $data = $row;
  50. }
  51. }
  52.  
  53. return $data;
  54. }
  55.  
  56. }
  57. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement