diff options
Diffstat (limited to 'installer/libraries')
-rw-r--r-- | installer/libraries/Install_Mysql_Driver.php | 32 | ||||
-rw-r--r-- | installer/libraries/Install_Mysqli_Driver.php | 34 |
2 files changed, 53 insertions, 13 deletions
diff --git a/installer/libraries/Install_Mysql_Driver.php b/installer/libraries/Install_Mysql_Driver.php index ae44e040..aac49acd 100644 --- a/installer/libraries/Install_Mysql_Driver.php +++ b/installer/libraries/Install_Mysql_Driver.php @@ -18,27 +18,47 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class Install_Mysql_Driver { - private $link; + private $_link; + private $_server; + private $_user; public function __construct($server, $user, $password) { - $this->link = @mysql_connect($server, $user, $password); - if (!$this->link) { + $this->_link = @mysql_connect($server, $user, $password); + if (!$this->_link) { throw new Exception(mysql_error()); } + $this->_server = $server; + $this->_user = $user; } public function __destruct() { - if (!empty($this->link)) { - @mysql_close($this->link); + if (!empty($this->_link)) { + @mysql_close($this->_link); } } public function list_dbs() { - $db_list = mysql_list_dbs($this->link); + $db_list = mysql_list_dbs($this->_link); $databases = array(); while ($row = mysql_fetch_object($db_list)) { $databases[$row->Database] = 1; } return $databases; } + + public function get_access_rights($dbname) { + $select = "SELECT PRIVILEGE_TYPE " . + " FROM `information_schema`.`schema_privileges`" . + " WHERE `GRANTEE` = '\\'{$this->_user}\\'@\\'{$this->_server}\\''" . + " AND `TABLE_SCHEMA` = '$dbname';"; + $privileges = mysql_query($select, $this->_link); + $permissions = array(); + if ($privileges) { + while ($row = mysql_fetch_assoc($privileges)) { + $permissions[strtolower($row["PRIVILEGE_TYPE"])] = 1; + } + } + return $permissions; + } + } diff --git a/installer/libraries/Install_Mysqli_Driver.php b/installer/libraries/Install_Mysqli_Driver.php index 114a42f4..ce141066 100644 --- a/installer/libraries/Install_Mysqli_Driver.php +++ b/installer/libraries/Install_Mysqli_Driver.php @@ -20,24 +20,28 @@ // Convienence wrapper around the Php mysqli class class Install_Mysqli_Driver { - private $mysqli; + private $_mysqli; + private $_server; + private $_user; public function __construct($server, $user, $password) { - $this->mysqli = @mysqli_connect($server, $user, $password); - if (!$this->mysqli) { + $this->_mysqli = @mysqli_connect($server, $user, $password); + if (!$this->_mysqli) { throw new Exception(mysqli_connect_error()); } + $this->_server = $server; + $this->_user = $user; } public function __destruct() { - if (!empty($this->mysqli)) { - @$this->mysqli->close(); - $this->mysqli = null; + if (!empty($this->_mysqli)) { + @$this->_mysqli->close(); + $this->_mysqli = null; } } public function list_dbs() { - $db_list = $this->mysqli->query("SHOW DATABASES"); + $db_list = $this->_mysqli->query("SHOW DATABASES"); $databases = array(); if ($db_list) { while ($row = $db_list->fetch_row()) { @@ -46,5 +50,21 @@ class Install_Mysqli_Driver { } return $databases; } + + public function get_access_rights($dbname) { + $select = "SELECT PRIVILEGE_TYPE " . + " FROM `information_schema`.`schema_privileges`" . + " WHERE `GRANTEE` = '\\'{$this->_user}\\'@\\'{$this->_server}\\''" . + " AND `TABLE_SCHEMA` = '$dbname';"; + $privileges = $this->_mysqli->query($select); + $permissions = array(); + if ($privileges) { + while ($row = $privileges->fetch_row()) { + $permissions[strtolower($row[0])] = 1; + } + } + return $permissions; + } + } |