123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- <?php
- class Server_Controller
- {
- protected $host = 'localhost';
- protected $user = 'root';
-
- protected $port = 3306;
-
-
- protected $pass = NULL;
-
- public $conn;
-
-
- public function __construct(array $arCred = array())
- {
- foreach ($arCred as $key => $val)
- {
- $this->$key = $val;
- }
- }
-
-
- public function login()
- {
- $this->conn = new PDO('mysql:host=' . $this->host
- . ';port=' . $this->port
- . ';dbname=mysql',
- $this->user,
- $this->pass);
- return (is_object($this->conn));
- }
-
-
- public function getDatabases()
- {
- $q = $this->conn->query('SHOW DATABASES');
- $ret = $q->fetchAll(PDO::FETCH_COLUMN, 0);
- $q->closeCursor();
- return $ret;
- }
-
-
- public function getStatus($key = NULL)
- {
- $q = $this->conn->query('SHOW STATUS');
- if (empty($key))
- {
- $ret = $q->fetchAll(PDO::FETCH_COLUMN, 0);
- $q->closeCursor();
- }
- else
- {
- $ret = NULL;
- while ($row = $q->fetch(PDO::FETCH_NUM))
- {
- if ($row[0] === $key)
- {
- $ret = $row[1];
- $q->closeCursor();
- break;
- }
- }
- }
- return $ret;
- }
-
-
- public function flushQueryCache($reset = FALSE)
- {
- $sq = ($reset ? 'RESET' : 'FLUSH') . ' QUERY CACHE';
- $ret = $this->conn->query($sq);
- $ret->closeCursor();
- }
- }
|