PHP MySQL Logging and Error Handling - Best Practice

I am creating a website using PHP that allows users to add a lot of data to various tables in a MYSQL database. This requires a lot of inserting, updating and deleting tables in my database, sometimes several commands are executed in one script.

I am worried about catching potential errors that occur in real time (I tested, tested and tested, but still want to create a backup plan).

I searched everywhere for a solution, but I can’t find one that will satisfy my needs, so I wondered if anyone has any methods that they use, or tips that they can give me.

What I want:

If an error occurs while connecting to my database (for example), I want to display a page or warning window with the message “sorry, we had a problem” with a button for registering the error. When the user clicks the button, I want to be able to write mysql_error () to the database with a description of the failed command / function and page name along with a time / date stamp that I can track.

Is this what someone has done before or can offer an alternative? Or is there a built-in function that does exactly that, which I missed?

Any advice would be highly appreciated.

+5
source share
1 answer

, db. , php mysql, (, PDO), try-catch , .

, Apache ( try-catch).

+5

All Articles