Guest User

Untitled

a guest
Dec 17th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. <?php
  2. class connection {
  3. private $_connection;
  4. private static $_instance; //The single instance
  5. private $_host = "localhost";
  6. private $_username = "username";
  7. private $_password = "password";
  8. private $_database = "database";
  9.  
  10. /*
  11. Get an instance of the Database
  12. @return Instance
  13. */
  14. public static function getInstance() {
  15. if(!self::$_instance) { // If no instance then make one
  16. self::$_instance = new self();
  17. }
  18. return self::$_instance;
  19. }
  20.  
  21. // Constructor
  22. private function __construct() {
  23. $this->_connection = new mysqli($this->_host, $this->_username,
  24. $this->_password, $this->_database);
  25. }
  26.  
  27. // Magic method clone is empty to prevent duplication of connection
  28. private function __clone() { }
  29.  
  30. // Get mysqli connection
  31. public function getConnection() {
  32. return $this->_connection;
  33. }
  34. }
  35. ?>
  36.  
  37. class login extends connection{
  38. private $conn;
  39. private $userid;
  40. public $loggedin;
  41.  
  42. function __construct($id){
  43. $this->userid = $id;
  44. $this->set_login();
  45. }
  46.  
  47. private function set_login(){
  48. $this->connect();
  49. $result = $this->conn->query("SELECT status FROM users WHERE userid='".$this->userid.'"');
  50. if($result){
  51. $this->loggedin = true;
  52. }else{
  53. $this->loggedin = false;
  54. }
  55. }
  56.  
  57. private function connect(){
  58. $this->conn = parent::getInstance()->getConnection();
  59. }
  60. }
  61.  
  62. <?php
  63. spl_autoload_register(function ($class) {
  64. include '../classes/' . $class . '.php';
  65. });
  66. $user = new login("75");
  67. if($user->logged_in){
  68. $db = connection::getInstance();
  69. $conn = $db->getConnection();
  70. $query = 'SHOW STATUS WHERE variable_name LIKE "Threads_%" OR variable_name = "Connections"';
  71. $result = $conn->query($query);
  72. while($row=$result->fetch_assoc()){
  73. echo $row['Variable_name'].' - '.$row['Value'].'<br />';
  74. }
  75. }
  76. ?>
  77.  
  78. Connections - 1026572
  79. Threads_cached - 7
  80. Threads_connected - 9
  81. Threads_created - 42943
  82. Threads_running - 2
Add Comment
Please, Sign In to add comment