Guest User

Untitled

a guest
Apr 22nd, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. <?php
  2. session_start();
  3. class Lib
  4. {
  5. private $host = "localhost"; // your host name
  6. private $username = "root"; // your user name
  7. private $password = ""; // your password
  8. private $db = "db_apti"; // your database name
  9. public $conn = '';
  10. public function __construct()
  11. {
  12. $conn = mysqli_connect($this->host, $this->username, $this->password,$this->db) or die(mysqli_connect_error());
  13.  
  14. }
  15.  
  16. protected function query_executed($sql)
  17. {
  18. $c = mysqli_query($this->conn,$sql);
  19. return $c;
  20. }
  21.  
  22. public function get_rows($fields, $id = NULL, $tablename = NULL)
  23. {
  24. $cn = !empty($id) ? " WHERE $id " : " ";
  25. $fields = !empty($fields) ? $fields : " * ";
  26. $sql = "SELECT $fields FROM $tablename $cn";
  27. $results = $this->query_executed($sql);
  28. $rows = $this->get_fetch_data($results);
  29. return $rows;
  30. }
  31.  
  32. protected function get_fetch_data($r)
  33. {
  34. $array = array();
  35. while ($rows = mysqli_fetch_assoc($r))
  36. {
  37. $array[] = $rows;
  38. }
  39. return $array;
  40. }
  41. }
  42.  
  43. $lib = new Lib(); //create class object here
  44.  
  45. ?>
Add Comment
Please, Sign In to add comment