N98\Util\Console\Helper\DatabaseHelper::getMysqlVariable PHP Method

getMysqlVariable() public method

in difference to @see getMysqlVariableValue(), this method allows to specify the type of the variable as well as to use any variable identifier even such that need quoting.
public getMysqlVariable ( string $name, string $type = null ) : string
$name string mysql variable name
$type string [optional] variable type, can be a system variable ("@@", default) or a session variable ("@").
return string variable value, null if variable was not defined
    public function getMysqlVariable($name, $type = null)
    {
        if (null === $type) {
            $type = "@@";
        } else {
            $type = (string) $type;
        }
        if (!in_array($type, array("@@", "@"), true)) {
            throw new InvalidArgumentException(sprintf('Invalid mysql variable type "%s", must be "@@" (system) or "@" (session)', $type));
        }
        $quoted = '`' . strtr($name, array('`' => '``')) . '`';
        $query = "SELECT {$type}{$quoted};";
        $connection = $this->getConnection();
        $statement = $connection->query($query, PDO::FETCH_COLUMN, 0);
        if ($statement instanceof PDOStatement) {
            $result = $statement->fetchColumn(0);
        } else {
            $reason = $connection->errorInfo() ? vsprintf('SQLSTATE[%s]: %s: %s', $connection->errorInfo()) : 'no error info';
            throw new RuntimeException(sprintf('Failed to query mysql variable %s: %s', var_export($name, true), $reason));
        }
        return $result;
    }