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;
}