/** * Convenience method to prepare and execute a query * * <b>Note:</b> On failure, and if the $failDie parameter is set to TRUE, this * function sends a mail to the administrator with some relevant information * such as the debug information if the * {@link EasySCP_Exception_Writer_Mail writer} is active. * * @throws EasySCP_Exception_Database * @param EasySCP_Database $db EasySCP_Database Instance * @param string $query SQL statement * @param string|int|array $bind Data to bind to the placeholders * @param boolean $failDie If TRUE, throws an EasySCP_Exception_Database exception * on failure * @return EasySCP_Database_ResultSet Return a EasySCP_Database_ResultSet object * that represents a result set or FALSE on failure if $failDie is set to FALSE */ function exec_query($db, $query, $bind = null, $failDie = true) { if (!($stmt = $db->prepare($query)) || !($stmt = $db->execute($stmt, $bind))) { if ($failDie) { throw new EasySCP_Exception($db->getLastErrorMessage() . " - Query: {$query}"); } } return $stmt; }