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

Minor improvements to SimpleSAML\Database.

parent 84547358
No related branches found
No related tags found
No related merge requests found
......@@ -2,17 +2,15 @@
namespace SimpleSAML;
/**
* This file implements functions to read and write to a group of database
* servers.
* This file implements functions to read and write to a group of database servers.
*
* This database class supports a single database, or a master/slave
* configuration with as many defined slaves as a user would like.
* This database class supports a single database, or a master/slave configuration with as many defined slaves as a
* user would like.
*
* The goal of this class is to provide a single mechanism to connect to a database
* that can be reused by any component within SimpleSAMLphp including modules.
* When using this class, the global configuration should be passed here, but
* in the case of a module that has a good reason to use a different database,
* such as sqlauth, an alternative config file can be provided.
* The goal of this class is to provide a single mechanism to connect to a database that can be reused by any component
* within SimpleSAMLphp including modules. When using this class, the global configuration should be passed here, but in
* the case of a module that has a good reason to use a different database, such as sqlauth, an alternative config file
* can be provided.
*
* @author Tyler Antonio, University of Alberta. <tantonio@ualberta.ca>
* @package SimpleSAMLphp
......@@ -32,8 +30,7 @@ class Database
private $dbMaster;
/**
* Array of PDO Objects for configured database
* slaves
* Array of PDO Objects for configured database slaves
*/
private $dbSlaves = array();
......@@ -112,8 +109,7 @@ class Database
/**
* Generate an Instance ID based on the database
* configuration.
* Generate an Instance ID based on the database configuration.
*
* @param \SimpleSAML_Configuration $config Configuration class
*
......@@ -161,9 +157,8 @@ class Database
/**
* This function randomly selects a slave database server
* to query. In the event no slaves are configured, it
* will return the master.
* This function randomly selects a slave database server to query. In the event no slaves are configured, it will
* return the master.
*
* @return \PDO object
*/
......@@ -229,14 +224,13 @@ class Database
/**
* This function queries the database without using a
* prepared statement.
* This function queries the database without using a prepared statement.
*
* @param \PDO $db PDO object to use
* @param string $stmt Prepared SQL statement
* @param string $stmt An SQL statement to execute, previously escaped.
*
* @throws \Exception If an error happens while trying to execute the query.
* @return \PDOStatement object
* @return int The number of rows affected.
*/
private function exec($db, $stmt)
{
......@@ -244,9 +238,7 @@ class Database
assert('is_string($stmt)');
try {
$query = $db->exec($stmt);
return $query;
return $db->exec($stmt);
} catch (\PDOException $e) {
$this->lastError = $db->errorInfo();
throw new \Exception("Database error: ".$e->getMessage());
......@@ -276,8 +268,7 @@ class Database
/**
* This executes queries on a database server
* that is determined by this::getSlave()
* This executes queries on a database server that is determined by this::getSlave().
*
* @param string $stmt Prepared SQL statement
* @param array $params Parameters
......
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