If I change the SQL just to one line like “BLAH BLAH BLAH;” the PDO is thrown
I read somewhere that all the rows in the the resultset has to be fetched in order to get invidual exceptions of each line. But I can’t find any example.
To a redirect you choose, but if a user is getting PDO error, I have them contact admin.
To note, I use cake, laravel, and yii2 and also use the PDO instance in all three for thngs like reports. I have never wrapped a try catch around PDO, and have never had any errors.
But cake’s error handling is dealing with the errors. I would not mess with cake’s build in handling of errors, the Cakephp team knew what they were doing.
Hi, thanks for the answer. The reason why I want to catch the Exception is that I’m calling the controller method as a Shell task that inserts many records on the database and I need to know of some of the inserts failed.
I also want to wrap it in a transaction, but the problem occurs anyway.
The issue is that when the SQL string has more than one command and it has a syntax error somewhere, no exception is thrown. Even without try catch, when calling the action directly on the browser, no exception or error is thrown.
Anyway, I found out that if I split each sql command and call them individually, It works as expected