PMA\libraries\DatabaseInterface::getConnectionParams PHP Méthode

getConnectionParams() public méthode

Return connection parameters for the database server
public getConnectionParams ( integer $mode, array $server = null ) : array
$mode integer Connection mode on of CONNECT_USER, CONNECT_CONTROL or CONNECT_AUXILIARY.
$server array Server information like host/port/socket/persistent
Résultat array user, host and server settings array
    public function getConnectionParams($mode, $server = null)
    {
        global $cfg;
        $user = null;
        $password = null;
        if ($mode == DatabaseInterface::CONNECT_USER) {
            $user = $cfg['Server']['user'];
            $password = $cfg['Server']['password'];
            $server = $cfg['Server'];
        } elseif ($mode == DatabaseInterface::CONNECT_CONTROL) {
            $user = $cfg['Server']['controluser'];
            $password = $cfg['Server']['controlpass'];
            $server = array();
            if (!empty($cfg['Server']['controlhost'])) {
                $server['host'] = $cfg['Server']['controlhost'];
            } else {
                $server['host'] = $cfg['Server']['host'];
            }
            // Share the settings if the host is same
            if ($server['host'] == $cfg['Server']['host']) {
                $shared = array('port', 'socket', 'connect_type', 'compress', 'ssl', 'ssl_key', 'ssl_cert', 'ssl_ca', 'ssl_ca_path', 'ssl_ciphers', 'ssl_verify');
                foreach ($shared as $item) {
                    if (isset($cfg['Server'][$item])) {
                        $server[$item] = $cfg['Server'][$item];
                    }
                }
            }
            // Set configured port
            if (!empty($cfg['Server']['controlport'])) {
                $server['port'] = $cfg['Server']['controlport'];
            }
            // Set any configuration with control_ prefix
            foreach ($cfg['Server'] as $key => $val) {
                if (substr($key, 0, 8) === 'control_') {
                    $server[substr($key, 8)] = $val;
                }
            }
        } else {
            if (is_null($server)) {
                return array(null, null, null);
            }
            if (isset($server['user'])) {
                $user = $server['user'];
            }
            if (isset($server['password'])) {
                $password = $server['password'];
            }
        }
        // Perform sanity checks on some variables
        if (empty($server['port'])) {
            $server['port'] = 0;
        } else {
            $server['port'] = intval($server['port']);
        }
        if (empty($server['socket'])) {
            $server['socket'] = null;
        }
        if (empty($server['host'])) {
            $server['host'] = 'localhost';
        }
        if (!isset($server['ssl'])) {
            $server['ssl'] = false;
        }
        if (!isset($server['compress'])) {
            $server['compress'] = false;
        }
        return array($user, $password, $server);
    }