• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 308
  • Last Modified:

separate logs for pdo

using pdo, is there a way to have a log of errors and a log of dbquery and a log of dbfetch
2 Solutions
Julian HansenCommented:
Do you mean automatically?

Not  that I am aware of - read this to see what the issues are

Ray PaseurCommented:
Yes, of course!  This would be true of PDO, MySQLi or any other data base API.  You can extend any of the data base classes to add your own query() method.  The extension would be the correct place to use error logging.  

Most of the PHP code I've seen does not even test for errors.  The error indicators are set in the environment, but it is up to the client script to decide whether and how to use the indicators.  While this sounds confusing (why set an error indicator but not log it?) it actually makes a lot of sense once you get to understand a bit about application development.  

Let's say we had a built-in error handler that raised warnings and wrote error logs whenever, for example, MySQL encountered an error.  MySQL raises error number 1054 for an attempt to insert a duplicate value into a UNIQUE column.  Is this really an error that needs to be logged?  Probably not -- the app developer may have relied on the UNIQUE constraint to avoid duplicates, and the attempt does not represent an error in the application design (think UNIQUE user-ids, for example).  The attempt would be something that the application would detect and handle, not something that the data base extension should flag as a failure.

If your script extended the query() method to add error handling, the #1054 error would be handled differently from the other MySQL errors, so it would be your privilege and responsibility to write clear rules for what should be logged or reported.
rgb192Author Commented:
Now i can look into pdo logging with these examples

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now