Skip to content
This repository was archived by the owner on Feb 4, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion code/database/driver/abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,20 @@ abstract function setDatabase($database);
* Provides access to the underlying database connection. Useful for when
* you need to call a proprietary method such as postgresql's lo_* methods
*
* @param bool $auto_connect If connection hasn't been established, auto connect
* @return resource
* @throws \RuntimeException if auto connection fails
*/
public function getConnection()
public function getConnection($auto_connect = true)
{
if (!$this->isConnected() && $auto_connect) {
$this->connect();

if (!$this->isConnected()) {
throw new \RuntimeException('Database auto connection failed');
}
}

return $this->_connection;
}

Expand Down
4 changes: 3 additions & 1 deletion code/database/driver/interface.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ public function disconnect();
* Provides access to the underlying database connection. Useful for when you need to call a proprietary method
* on the database driver
*
* @param bool $auto_connect If connection hasn't been established, auto connect
* @return resource
* @throws \RuntimeException if auto connection fails
*/
public function getConnection();
public function getConnection($auto_connect = true);

/**
* Set the connection
Expand Down