Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class connection {
- private $_connection;
- private static $_instance; //The single instance
- private $_host = "localhost";
- private $_username = "username";
- private $_password = "password";
- private $_database = "database";
- /*
- Get an instance of the Database
- @return Instance
- */
- public static function getInstance() {
- if(!self::$_instance) { // If no instance then make one
- self::$_instance = new self();
- }
- return self::$_instance;
- }
- // Constructor
- private function __construct() {
- $this->_connection = new mysqli($this->_host, $this->_username,
- $this->_password, $this->_database);
- }
- // Magic method clone is empty to prevent duplication of connection
- private function __clone() { }
- // Get mysqli connection
- public function getConnection() {
- return $this->_connection;
- }
- }
- ?>
- class login extends connection{
- private $conn;
- private $userid;
- public $loggedin;
- function __construct($id){
- $this->userid = $id;
- $this->set_login();
- }
- private function set_login(){
- $this->connect();
- $result = $this->conn->query("SELECT status FROM users WHERE userid='".$this->userid.'"');
- if($result){
- $this->loggedin = true;
- }else{
- $this->loggedin = false;
- }
- }
- private function connect(){
- $this->conn = parent::getInstance()->getConnection();
- }
- }
- <?php
- spl_autoload_register(function ($class) {
- include '../classes/' . $class . '.php';
- });
- $user = new login("75");
- if($user->logged_in){
- $db = connection::getInstance();
- $conn = $db->getConnection();
- $query = 'SHOW STATUS WHERE variable_name LIKE "Threads_%" OR variable_name = "Connections"';
- $result = $conn->query($query);
- while($row=$result->fetch_assoc()){
- echo $row['Variable_name'].' - '.$row['Value'].'<br />';
- }
- }
- ?>
- Connections - 1026572
- Threads_cached - 7
- Threads_connected - 9
- Threads_created - 42943
- Threads_running - 2
Add Comment
Please, Sign In to add comment