|
37 | 37 | * @package MagicObject\Database |
38 | 38 | * @link https://github.com/Planetbiru/MagicObject |
39 | 39 | */ |
40 | | -class PicoDatabase //NOSONAR |
| 40 | +class PicoDatabase // NOSONAR |
41 | 41 | { |
42 | 42 | const QUERY_INSERT = "insert"; |
43 | 43 | const QUERY_UPDATE = "update"; |
@@ -735,22 +735,13 @@ public function fetchAll($sql, $tentativeType = PDO::FETCH_ASSOC, $defaultValue |
735 | 735 | * |
736 | 736 | * @param string $sql SQL query to be executed. |
737 | 737 | * @param array|null $params Optional parameters to bind to the SQL query. |
| 738 | + * @return PDOStatement|false Returns the PDOStatement object if successful, or `false` on failure. |
738 | 739 | * @throws NullPointerException If the database connection is null. |
| 740 | + * @throws PDOException If an error occurs while executing the query. |
739 | 741 | */ |
740 | 742 | public function execute($sql, $params = null) |
741 | 743 | { |
742 | | - if ($this->databaseConnection == null) { |
743 | | - throw new NullPointerException(self::DATABASE_NONECTION_IS_NULL); |
744 | | - } |
745 | | - |
746 | | - $this->executeDebug($sql, $params); |
747 | | - $stmt = $this->databaseConnection->prepare($sql); |
748 | | - |
749 | | - try { |
750 | | - $stmt->execute($params); |
751 | | - } catch (PDOException $e) { |
752 | | - // Handle exception as needed |
753 | | - } |
| 744 | + return $this->executeQuery($sql, $params); |
754 | 745 | } |
755 | 746 |
|
756 | 747 | /** |
@@ -898,8 +889,7 @@ private function executeDebug($query, $params = null) |
898 | 889 | else |
899 | 890 | { |
900 | 891 | call_user_func($this->callbackDebugQuery, $query); |
901 | | - } |
902 | | - |
| 892 | + } |
903 | 893 | } |
904 | 894 | } |
905 | 895 |
|
|
0 commit comments