Known types are: MariaDB and MySQL (default)
public static getServerType ( ) : string | ||
Résultat | string |
/** * Get SQL queries for Display and Add user * * @param string $username username * @param string $hostname host name * @param string $password password * * @return array ($create_user_real, $create_user_show,$real_sql_query, $sql_query * $password_set_real, $password_set_show) */ function PMA_getSqlQueriesForDisplayAndAddUser($username, $hostname, $password) { $slashedUsername = Util::sqlAddSlashes($username); $slashedHostname = Util::sqlAddSlashes($hostname); $slashedPassword = Util::sqlAddSlashes($password); $serverType = Util::getServerType(); $create_user_stmt = sprintf('CREATE USER \'%s\'@\'%s\'', $slashedUsername, $slashedHostname); // See https://github.com/phpmyadmin/phpmyadmin/pull/11560#issuecomment-147158219 // for details regarding details of syntax usage for various versions // 'IDENTIFIED WITH auth_plugin' // is supported by MySQL 5.5.7+ if (($serverType == 'MySQL' || $serverType == 'Percona Server') && PMA_MYSQL_INT_VERSION >= 50507 && isset($_REQUEST['authentication_plugin'])) { $create_user_stmt .= ' IDENTIFIED WITH ' . $_REQUEST['authentication_plugin']; } // 'IDENTIFIED VIA auth_plugin' // is supported by MariaDB 5.2+ if ($serverType == 'MariaDB' && PMA_MYSQL_INT_VERSION >= 50200 && isset($_REQUEST['authentication_plugin'])) { $create_user_stmt .= ' IDENTIFIED VIA ' . $_REQUEST['authentication_plugin']; } $create_user_real = $create_user_show = $create_user_stmt; $password_set_stmt = 'SET PASSWORD FOR \'%s\'@\'%s\' = \'%s\''; $password_set_show = sprintf($password_set_stmt, $slashedUsername, $slashedHostname, '***'); $sql_query_stmt = sprintf('GRANT %s ON *.* TO \'%s\'@\'%s\'', join(', ', PMA_extractPrivInfo()), $slashedUsername, $slashedHostname); $real_sql_query = $sql_query = $sql_query_stmt; // Set the proper hashing method if (isset($_REQUEST['authentication_plugin'])) { PMA_setProperPasswordHashing($_REQUEST['authentication_plugin']); } // Use 'CREATE USER ... WITH ... AS ..' syntax for // newer MySQL versions // and 'CREATE USER ... USING .. VIA ..' syntax for // newer MariaDB versions if (($serverType == 'MySQL' || $serverType == 'Percona Server') && PMA_MYSQL_INT_VERSION >= 50706 || $serverType == 'MariaDB' && PMA_MYSQL_INT_VERSION >= 50200) { $password_set_real = null; // Required for binding '%' with '%s' $create_user_stmt = str_replace('%', '%%', $create_user_stmt); // MariaDB uses 'USING' whereas MySQL uses 'AS' if ($serverType == 'MariaDB') { $create_user_stmt .= ' USING \'%s\''; } else { $create_user_stmt .= ' AS \'%s\''; } if ($_POST['pred_password'] == 'keep') { $create_user_real = sprintf($create_user_stmt, $slashedPassword); $create_user_show = sprintf($create_user_stmt, '***'); } else { if ($_POST['pred_password'] == 'none') { $create_user_real = sprintf($create_user_stmt, null); $create_user_show = sprintf($create_user_stmt, '***'); } else { $hashedPassword = PMA_getHashedPassword($_POST['pma_pw']); $create_user_real = sprintf($create_user_stmt, $hashedPassword); $create_user_show = sprintf($create_user_stmt, '***'); } } } else { // Use 'SET PASSWORD' syntax for pre-5.7.6 MySQL versions // and pre-5.2.0 MariaDB versions if ($_POST['pred_password'] == 'keep') { $password_set_real = sprintf($password_set_stmt, $slashedUsername, $slashedHostname, $slashedPassword); } else { if ($_POST['pred_password'] == 'none') { $password_set_real = sprintf($password_set_stmt, $slashedUsername, $slashedHostname, null); } else { $hashedPassword = PMA_getHashedPassword($_POST['pma_pw']); $password_set_real = sprintf($password_set_stmt, $slashedUsername, $slashedHostname, $hashedPassword); } } } // add REQUIRE clause $require_clause = PMA_getRequireClause(); $real_sql_query .= $require_clause; $sql_query .= $require_clause; if (isset($_POST['Grant_priv']) && $_POST['Grant_priv'] == 'Y' || (isset($_POST['max_questions']) || isset($_POST['max_connections']) || isset($_POST['max_updates']) || isset($_POST['max_user_connections']))) { $with_clause = PMA_getWithClauseForAddUserAndUpdatePrivs(); $real_sql_query .= $with_clause; $sql_query .= $with_clause; } if (isset($create_user_real)) { $create_user_real .= ';'; $create_user_show .= ';'; } $real_sql_query .= ';'; $sql_query .= ';'; // No Global GRANT_OPTION privilege if (!$GLOBALS['is_grantuser']) { $real_sql_query = ''; $sql_query = ''; } // Use 'SET PASSWORD' for pre-5.7.6 MySQL versions // and pre-5.2.0 MariaDB if ($serverType == 'MySQL' && PMA_MYSQL_INT_VERSION >= 50706 || $serverType == 'MariaDB' && PMA_MYSQL_INT_VERSION >= 50200) { $password_set_real = null; $password_set_show = null; } else { $password_set_real .= ";"; $password_set_show .= ";"; } return array($create_user_real, $create_user_show, $real_sql_query, $sql_query, $password_set_real, $password_set_show); }
/** * Returns array of all column types available. * * VARCHAR, TINYINT, TEXT and DATE are listed first, based on * estimated popularity. * * @return string[] * */ public function getColumns() { $ret = parent::getColumns(); // numeric $ret[_pgettext('numeric types', 'Numeric')] = array('TINYINT', 'SMALLINT', 'MEDIUMINT', 'INT', 'BIGINT', '-', 'DECIMAL', 'FLOAT', 'DOUBLE', 'REAL', '-', 'BIT', 'BOOLEAN', 'SERIAL'); // Date/Time $ret[_pgettext('date and time types', 'Date and time')] = array('DATE', 'DATETIME', 'TIMESTAMP', 'TIME', 'YEAR'); // Text $ret[_pgettext('string types', 'String')] = array('CHAR', 'VARCHAR', '-', 'TINYTEXT', 'TEXT', 'MEDIUMTEXT', 'LONGTEXT', '-', 'BINARY', 'VARBINARY', '-', 'TINYBLOB', 'MEDIUMBLOB', 'BLOB', 'LONGBLOB', '-', 'ENUM', 'SET'); $ret[_pgettext('spatial types', 'Spatial')] = array('GEOMETRY', 'POINT', 'LINESTRING', 'POLYGON', 'MULTIPOINT', 'MULTILINESTRING', 'MULTIPOLYGON', 'GEOMETRYCOLLECTION'); if (PMA_MYSQL_INT_VERSION >= 50708 && \PMA\libraries\Util::getServerType() != 'MariaDB') { $ret['JSON'] = array('JSON'); } return $ret; }
/** * Returns the generation expression for virtual columns * * @param string $column name of the column * * @return array|boolean associative array of column name and their expressions * or false on failure */ public function getColumnGenerationExpression($column = null) { $serverType = Util::getServerType(); if ($serverType == 'MySQL' && PMA_MYSQL_INT_VERSION > 50705 && !$GLOBALS['cfg']['Server']['DisableIS']) { $sql = "SELECT\n `COLUMN_NAME` AS `Field`,\n `GENERATION_EXPRESSION` AS `Expression`\n FROM\n `information_schema`.`COLUMNS`\n WHERE\n `TABLE_SCHEMA` = '" . Util::sqlAddSlashes($this->_db_name) . "'\n AND `TABLE_NAME` = '" . Util::sqlAddSlashes($this->_name) . "'"; if ($column != null) { $sql .= " AND `COLUMN_NAME` = '" . Util::sqlAddSlashes($column) . "'"; } $columns = $this->_dbi->fetchResult($sql, 'Field', 'Expression'); return $columns; } $createTable = $this->showCreate(); if (!$createTable) { return false; } $parser = new Parser($createTable); /** * @var \SqlParser\Statements\CreateStatement $stmt */ $stmt = $parser->statements[0]; $fields = Table::getFields($stmt); if ($column != null) { $expression = isset($fields[$column]['expr']) ? substr($fields[$column]['expr'], 1, -1) : ''; return array($column => $expression); } $ret = array(); foreach ($fields as $field => $options) { if (isset($options['expr'])) { $ret[$field] = substr($options['expr'], 1, -1); } } return $ret; }
/** * Get SQL queries for Display and Add user * * @param string $username username * @param string $hostname host name * @param string $password password * * @return array ($create_user_real, $create_user_show,$real_sql_query, $sql_query * $password_set_real, $password_set_show) */ function PMA_getSqlQueriesForDisplayAndAddUser($username, $hostname, $password) { $slashedUsername = Util::sqlAddSlashes($username); $slashedHostname = Util::sqlAddSlashes($hostname); $slashedPassword = Util::sqlAddSlashes($password); $serverType = Util::getServerType(); $create_user_stmt = sprintf('CREATE USER \'%s\'@\'%s\'', $slashedUsername, $slashedHostname); if (PMA_MYSQL_INT_VERSION >= 50507 && $serverType == 'MySQL' && isset($_REQUEST['authentication_plugin'])) { $create_user_stmt .= ' IDENTIFIED WITH ' . $_REQUEST['authentication_plugin']; } if (PMA_MYSQL_INT_VERSION >= 50707 && $serverType == 'MySQL' && strpos($create_user_stmt, '%') !== false) { $create_user_stmt = str_replace('%', '%%', $create_user_stmt); } $create_user_real = $create_user_show = $create_user_stmt; $password_set_stmt = 'SET PASSWORD FOR \'%s\'@\'%s\' = PASSWORD(\'%s\')'; $password_set_show = sprintf($password_set_stmt, $slashedUsername, $slashedHostname, '***'); $sql_query_stmt = sprintf('GRANT %s ON *.* TO \'%s\'@\'%s\'', join(', ', PMA_extractPrivInfo()), $slashedUsername, $slashedHostname); $real_sql_query = $sql_query = $sql_query_stmt; if (PMA_MYSQL_INT_VERSION < 50707 || $serverType != 'MySQL') { if ($_POST['pred_password'] == 'keep') { $password_set_real = sprintf($password_set_stmt, $slashedUsername, $slashedHostname, $slashedPassword); } else { if ($_POST['pred_password'] == 'none') { $password_set_real = sprintf($password_set_stmt, $slashedUsername, $slashedHostname, null); } else { $password_set_real = sprintf($password_set_stmt, $slashedUsername, $slashedHostname, $_POST['pma_pw']); } } } else { $password_set_real = null; $create_user_stmt .= ' BY \'%s\''; if ($_POST['pred_password'] == 'keep') { $create_user_real = sprintf($create_user_stmt, $password); $create_user_show = sprintf($create_user_stmt, '***'); } else { if ($_POST['pred_password'] == 'none') { $create_user_real = sprintf($create_user_stmt, null); $create_user_show = sprintf($create_user_stmt, '***'); } else { $create_user_real = sprintf($create_user_stmt, $_POST['pma_pw']); $create_user_show = sprintf($create_user_stmt, '***'); } } } // add REQUIRE clause $require_clause = PMA_getRequireClause(); $real_sql_query .= $require_clause; $sql_query .= $require_clause; if (isset($_POST['Grant_priv']) && $_POST['Grant_priv'] == 'Y' || (isset($_POST['max_questions']) || isset($_POST['max_connections']) || isset($_POST['max_updates']) || isset($_POST['max_user_connections']))) { $with_clause = PMA_getWithClauseForAddUserAndUpdatePrivs(); $real_sql_query .= $with_clause; $sql_query .= $with_clause; } if (isset($create_user_real)) { $create_user_real .= ';'; $create_user_show .= ';'; } $real_sql_query .= ';'; $sql_query .= ';'; // No Global GRANT_OPTION privilege if (!$GLOBALS['is_grantuser']) { $real_sql_query = ''; $sql_query = ''; } if ($serverType == 'MySQL' && PMA_MYSQL_INT_VERSION >= 50700) { $password_set_real = null; $password_set_show = null; } else { $password_set_real .= ";"; $password_set_show .= ";"; } return array($create_user_real, $create_user_show, $real_sql_query, $sql_query, $password_set_real, $password_set_show); }