You are here

protected function MysqlProfilerStorage::initDb in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/http-kernel/Profiler/MysqlProfilerStorage.php \Symfony\Component\HttpKernel\Profiler\MysqlProfilerStorage::initDb()

Initializes the database.

Throws

\RuntimeException When the requested database driver is not installed

Overrides PdoProfilerStorage::initDb

File

vendor/symfony/http-kernel/Profiler/MysqlProfilerStorage.php, line 24

Class

MysqlProfilerStorage
A ProfilerStorage for Mysql.

Namespace

Symfony\Component\HttpKernel\Profiler

Code

protected function initDb() {
  if (null === $this->db) {
    if (0 !== strpos($this->dsn, 'mysql')) {
      throw new \RuntimeException(sprintf('Please check your configuration. You are trying to use Mysql with an invalid dsn "%s". The expected format is "mysql:dbname=database_name;host=host_name".', $this->dsn));
    }
    if (!class_exists('PDO') || !in_array('mysql', \PDO::getAvailableDrivers(), true)) {
      throw new \RuntimeException('You need to enable PDO_Mysql extension for the profiler to run properly.');
    }
    $db = new \PDO($this->dsn, $this->username, $this->password);
    $db
      ->exec('CREATE TABLE IF NOT EXISTS sf_profiler_data (token VARCHAR(255) PRIMARY KEY, data LONGTEXT, ip VARCHAR(64), method VARCHAR(6), url VARCHAR(255), time INTEGER UNSIGNED, parent VARCHAR(255), created_at INTEGER UNSIGNED, status_code SMALLINT UNSIGNED, KEY (created_at), KEY (ip), KEY (method), KEY (url), KEY (parent))');
    $this->db = $db;
  }
  return $this->db;
}