Problem with transactions try catch |
I have a table that has a unique field, which I use to check that no identical insertions are made, this query is executed in the save_res method which is called within the transaction, as per the simplified example code.
Code in the model PHP Code: public function my_method($jsonData) Simulating an insertion with key duplication, I would expect that the transaction would fail and therefore all the queries would rollback and that my log message would therefore be written in the log file, but this does not happen, in the log file I find the system log reporting the uniqueness violation, but the catch part is never executed. I also tried to transfer all the code of the save_res method into the my_method method, but nothing changes. I don't understand why when the query that violates uniqueness goes into error, this doesn't trigger the catch part, or why it doesn't go into error even though the error is correctly reported in the log file. Code: ERROR - 2024-01-10 17:13:42 --> mysqli_sql_exception: Duplicate entry '2024-01-10-10:30:00' for key 'unique_data_time'
Try the code below using DatabaseException.
PHP Code: <?php What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
(01-10-2024, 10:34 AM)InsiteFX Wrote: Try the code below using DatabaseException. I was just rereading the documentation and saw Since v4.3.0, during transactions, exceptions are not thrown by default even if DDBebug is true. Thanks |
Welcome Guest, Not a member yet? Register Sign In |