Skip to content
Snippets Groups Projects
Commit e2edba3c authored by Jaime Perez Crespo's avatar Jaime Perez Crespo
Browse files

Fix some more phpdoc issues with returned values. Add a getLastError() method...

Fix some more phpdoc issues with returned values. Add a getLastError() method to retrieve information about the last error occurred.
parent 5f5b45ae
No related branches found
No related tags found
No related merge requests found
......@@ -42,6 +42,11 @@ class Database
*/
private $tablePrefix;
/**
* Array with information on the last error occurred.
*/
private $lastError;
/**
* Retrieves the current database instance. Will create a new one if there isn't an existing connection.
......@@ -194,7 +199,7 @@ class Database
* @param array $params Parameters
*
* @throws \Exception If an error happens while trying to execute the query.
* @return \PDO statement object
* @return \PDOStatement object
*/
private function query($db, $stmt, $params)
{
......@@ -217,6 +222,7 @@ class Database
return $query;
} catch (\PDOException $e) {
$this->lastError = $db->errorInfo();
throw new \Exception("Database error: ".$e->getMessage());
}
}
......@@ -230,7 +236,7 @@ class Database
* @param string $stmt Prepared SQL statement
*
* @throws \Exception If an error happens while trying to execute the query.
* @return \PDO statement object
* @return \PDOStatement object
*/
private function exec($db, $stmt)
{
......@@ -242,6 +248,7 @@ class Database
return $query;
} catch (\PDOException $e) {
$this->lastError = $db->errorInfo();
throw new \Exception("Database error: ".$e->getMessage());
}
}
......@@ -253,7 +260,7 @@ class Database
* @param string $stmt Prepared SQL statement
* @param array $params Parameters
*
* @return \PDO statement object
* @return \PDOStatement object
*/
public function write($stmt, $params = array())
{
......@@ -274,7 +281,7 @@ class Database
* @param string $stmt Prepared SQL statement
* @param array $params Parameters
*
* @return \PDO statement object
* @return \PDOStatement object
*/
public function read($stmt, $params = array())
{
......@@ -282,4 +289,15 @@ class Database
return $this->query($db, $stmt, $params);
}
/**
* Return an array with information about the last operation performed in the database.
*
* @return array The array with error information.
*/
public function getLastError()
{
return $this->lastError;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment