Commit 2a6d8fab by Scott

Fix qa_db_connection and auto-connect in DbConnection

parent 915ee0a9
......@@ -80,7 +80,12 @@ function qa_db_connection($connect = true)
{
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
return qa_service('database');
$db = qa_service('database');
if ($connect && !$db->isConnected()) {
$db->connect();
}
return $db;
}
......
......@@ -82,6 +82,15 @@ class DbConnection
}
/**
* Indicates whether Q2A is connected to the database.
* @return boolean
*/
public function isConnected()
{
return $this->pdo !== null;
}
/**
* Connect to the Q2A database, optionally install the $failHandler (and call it if necessary). Uses PDO as of Q2A
* 1.9.
* @param string $failHandler
......@@ -124,7 +133,7 @@ class DbConnection
}
/**
* Disconnect from the Q2A database.
* Disconnect from the Q2A database. This is not strictly required, but we do it in case there is a long Q2A shutdown process.
* @return void
*/
public function disconnect()
......@@ -166,6 +175,10 @@ class DbConnection
*/
public function query($query, $params = array())
{
if (!$this->isConnected()) {
$this->connect();
}
$query = $this->applyTableSub($query);
// handle old-style placeholders
$query = str_replace(['#', '$'], '?', $query);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment