4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\HttpKernel\Profiler;
14 @trigger_error('The '.__NAMESPACE__.'\MysqlProfilerStorage class is deprecated since Symfony 2.8 and will be removed in 3.0. Use FileProfilerStorage instead.', E_USER_DEPRECATED);
17 * A ProfilerStorage for Mysql.
19 * @author Jan Schumann <js@schumann-it.com>
21 * @deprecated Deprecated since Symfony 2.8, to be removed in Symfony 3.0.
22 * Use {@link FileProfilerStorage} instead.
24 class MysqlProfilerStorage extends PdoProfilerStorage
29 protected function initDb()
31 if (null === $this->db) {
32 if (0 !== strpos($this->dsn, 'mysql')) {
33 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));
36 if (!class_exists('PDO') || !in_array('mysql', \PDO::getAvailableDrivers(), true)) {
37 throw new \RuntimeException('You need to enable PDO_Mysql extension for the profiler to run properly.');
40 $db = new \PDO($this->dsn, $this->username, $this->password);
41 $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))');
52 protected function buildCriteria($ip, $url, $start, $end, $limit, $method)
57 if ($ip = preg_replace('/[^\d\.]/', '', $ip)) {
58 $criteria[] = 'ip LIKE :ip';
59 $args[':ip'] = '%'.$ip.'%';
63 $criteria[] = 'url LIKE :url';
64 $args[':url'] = '%'.addcslashes($url, '%_\\').'%';
68 $criteria[] = 'method = :method';
69 $args[':method'] = $method;
73 $criteria[] = 'time >= :start';
74 $args[':start'] = $start;
78 $criteria[] = 'time <= :end';
82 return array($criteria, $args);