Skip to content
Snippets Groups Projects
Commit 45b27c84 authored by Tyler Antonio's avatar Tyler Antonio
Browse files

Added the exec function for SQL queries that don't need to be prepared

parent 00c62667
Branches
Tags
No related merge requests found
...@@ -99,6 +99,7 @@ class SimpleSAML_Database { ...@@ -99,6 +99,7 @@ class SimpleSAML_Database {
'database.dsn' => $config->getValue('database.dsn'), 'database.dsn' => $config->getValue('database.dsn'),
'database.username' => $config->getValue('database.username'), 'database.username' => $config->getValue('database.username'),
'database.password' => $config->getValue('database.password'), 'database.password' => $config->getValue('database.password'),
'database.prefix' => $config->getValue('database.prefix'),
'database.persistent' => $config->getValue('database.persistent'), 'database.persistent' => $config->getValue('database.persistent'),
), ),
'slaves' => $config->getValue('database.slaves'), 'slaves' => $config->getValue('database.slaves'),
...@@ -177,7 +178,7 @@ class SimpleSAML_Database { ...@@ -177,7 +178,7 @@ class SimpleSAML_Database {
$query->bindValue(":$param", $value[0], ($value[1])? $value[1] : PDO::PARAM_STR); $query->bindValue(":$param", $value[0], ($value[1])? $value[1] : PDO::PARAM_STR);
} }
else{ else{
$query->bindValue(":$param", $value, PDO::PARAM_STR); $query->bindValue(":$param", $value, PDO::PARAM_STR);
} }
} }
...@@ -193,6 +194,29 @@ class SimpleSAML_Database { ...@@ -193,6 +194,29 @@ class SimpleSAML_Database {
} }
} }
/**
* This function queries the database without using a
* prepared statement.
*
* @param $db PDO object to use
* @param $stmt Prepared SQL statement
* @param $params Parameters
*
* @return PDO statement object
*/
private function exec($db, $stmt){
assert('is_object($db)');
assert('is_string($stmt)');
try{
$query = $db->exec($stmt);
return $query;
} catch (PDOException $e){
throw new Exception("Database error: ". $e->getMessage());
}
}
/** /**
* This executes queries directly on the master. * This executes queries directly on the master.
* *
...@@ -204,7 +228,11 @@ class SimpleSAML_Database { ...@@ -204,7 +228,11 @@ class SimpleSAML_Database {
public function write($stmt, $params = array()){ public function write($stmt, $params = array()){
$db = $this->dbMaster; $db = $this->dbMaster;
return $this->query($db, $stmt, $params); if (is_array($params)) {
return $this->query($db, $stmt, $params);
} else {
return $this->exec($db, $stmt);
}
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment