php - Pdo Error Catching Try/Catch -


after looking using try catch blocks pdo statements benefit? slow code down?

i believe there should try catch around connection command in case database connection fails. there need try catch around each pre prepared statement? these should never change , never error out.

any thoughts?

i'm using php , mysql.

there no benefit this:

try {   // exec statement   // exec statement } catch (exception $e) {   // nothing } 

if aren't going error , provide reasonable solution, may let exception bubble application's main "something went wrong" error page.

but may want this:

// begin transaction try {   // exec statement   // exec statement   // commit transaction } catch (exception $e) {   // rollback transaction   // handle error or rethrow $e;  } 

and prepared statements can throw exceptions. perhaps unique key violated, or foreign key constraint is, etc.

but main point is, don't use exceptions hide or silence errors. use them catch error, process intelligently, , continue on accordingly.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -