Fixed (again !) execute

This commit is contained in:
Franck Allimant
2014-04-14 11:05:37 +02:00
parent 2e9d5b91b5
commit bb30a69932

View File

@@ -108,10 +108,21 @@ class Database
*
* @param string $sql SQL query
* @param array $args SQL request parameters (PDO style)
* @throws \RuntimeException|\PDOException if something goes wrong.
*/
public function execute($sql, $args = array())
{
$this->connection->query($sql, $args);
$stmt = $this->connection->prepare($sql);
if ($stmt === false) {
throw new \RuntimeException("Failed to prepare statement for $sql: " . print_r($this->connection->errorInfo(), 1));
}
$success = $stmt->execute($args);
if ($success === false || $stmt->errorCode() != 0) {
throw new \RuntimeException("Failed to execute SQL '$sql', arguments:" . print_r($args,1).", error:".print_r($stmt->errorInfo(), 1));
}
}
/**