args = [ $dsn, $username, $password, $options, $queries ]; // retain a profiler, instantiating a default one if needed if ($profiler === null) { $profiler = new Profiler(); } $this->setProfiler($profiler); // retain a query parser $parts = explode(':', $dsn); $parser = $this->newParser($parts[0]); $this->setParser($parser); // set quotes for identifier names $this->setQuoteName($parts[0]); } /** * * Connects to the database. * * @return null * */ public function connect() { if ($this->pdo) { return; } // connect $this->profiler->start(__FUNCTION__); list($dsn, $username, $password, $options, $queries) = $this->args; $this->pdo = new PDO($dsn, $username, $password, $options); $this->profiler->finish(); // connection-time queries foreach ($queries as $query) { $this->exec($query); } } /** * * Disconnects from the database. * * @return null * */ public function disconnect() { $this->profiler->start(__FUNCTION__); $this->pdo = null; $this->profiler->finish(); } /** * * The purpose of this method is to hide sensitive data from stack traces. * * @return array * */ public function __debugInfo() { return [ 'args' => [ $this->args[0], '****', '****', $this->args[3], $this->args[4], ] ]; } /** * * Return the inner PDO (if any) * * @return \PDO * */ public function getPdo() { $this->connect(); return $this->pdo; } }