public function connect()
{
if ($this->pdo) {
return;
}
try {
$this->pdo = new PDO($this->params[0], $this->params[1], $this->params[2], $this->options);
$this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
throw ConnectionException::from($e);
}
$class = empty($this->options['driverClass']) ? 'Nette\\Database\\Drivers\\' . ucfirst(str_replace('sql', 'Sql', $this->pdo->getAttribute(PDO::ATTR_DRIVER_NAME))) . 'Driver' : $this->options['driverClass'];
$this->driver = new $class($this, $this->options);
$this->preprocessor = new SqlPreprocessor($this);
$this->onConnect($this);
}
/** * @param string statement * @param array * @return ResultSet */ public function queryArgs($statement, array $params) { $this->connection->connect(); if ($params) { if (!$this->preprocessor) { $this->preprocessor = new SqlPreprocessor($this->connection); } array_unshift($params, $statement); list($statement, $params) = $this->preprocessor->process($params); } try { $result = new ResultSet($this->connection, $statement, $params); } catch (\PDOException $e) { $e->queryString = $statement; $this->connection->onQuery($this->connection, $e); throw $e; } $this->connection->onQuery($this->connection, $result); return $result; }