Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Model
- {
- private $db = null;
- protected $connection = null;
- public $instance = null;
- public function __construct() {
- $this->load_db('stat');
- }
- // Set session
- public function set_session($session_name, $value)
- {
- $_SESSION[$session_name] = $value;
- }
- // Fetch session
- public function session($session_name)
- {
- return $_SESSION[$session_name];
- }
- public function load_db($name)
- {
- // Include db file
- include('config.php');
- // echo $name;
- if($database[$name] != NULL)
- {
- $this->db = new mysqli($database[$name]['host'], $database[$name]['username'], $database[$name]['password'], $database[$name]['database']);
- //echo 'Connected to new database!';
- }
- else
- {
- die('The connection named : ' . $name . ' can not be found in the configurations.');
- }
- }
- public function load($name)
- {
- if($name != NULL)
- {
- if(file_exists(MODELS_PATH.$name.'.php'))
- {
- $loaded_model = include(MODELS_PATH.$name.'.php');
- //$this->instance = new $name();
- $this->instance = new $name();
- return new $name();
- }
- else
- {
- die('The model ' . $name . ' can not be found!');
- }
- }
- }
- //query->("SELECT");
- public function fetch_assoc() {
- if($this->instance) {
- return $this->instance->fetch_assoc();
- }
- else
- {
- echo 'fail fetch assoc';
- }
- }
- public function query($query) {
- $sql = $query;
- $this->instance = $this->db->query($sql);
- return $this->db->query($sql);
- }
- public function select($query) {
- $sql = $query;
- //echo $sql;
- $this->instance = $this->query($sql);
- //echo $this->db->error;
- //print_r($this->instance);
- return $this->instance;
- // $this->query()->num_rows();
- // $this->query()
- // $this->num
- //return $this;
- }
- public function num_rows()
- {
- if ( $this->instance ) {
- return $this->instance->num_rows;
- //return num_rows;
- } else {
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement