Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- class Lib
- {
- private $host = "localhost"; // your host name
- private $username = "root"; // your user name
- private $password = ""; // your password
- private $db = "db_apti"; // your database name
- public $conn = '';
- public function __construct()
- {
- $conn = mysqli_connect($this->host, $this->username, $this->password,$this->db) or die(mysqli_connect_error());
- }
- protected function query_executed($sql)
- {
- $c = mysqli_query($this->conn,$sql);
- return $c;
- }
- public function get_rows($fields, $id = NULL, $tablename = NULL)
- {
- $cn = !empty($id) ? " WHERE $id " : " ";
- $fields = !empty($fields) ? $fields : " * ";
- $sql = "SELECT $fields FROM $tablename $cn";
- $results = $this->query_executed($sql);
- $rows = $this->get_fetch_data($results);
- return $rows;
- }
- protected function get_fetch_data($r)
- {
- $array = array();
- while ($rows = mysqli_fetch_assoc($r))
- {
- $array[] = $rows;
- }
- return $array;
- }
- }
- $lib = new Lib(); //create class object here
- ?>
Add Comment
Please, Sign In to add comment