Take the 2-minute tour ×

I'm building a page in a admin panel to display any php exceptions that occurred. This way they can be hidden from guests, but administrators can still review them.

But I can't decide if it's best to store them in a database or store them to a file? A database will definitively be easier to work with.

share|improve this question

closed as not a real question by George Stocker Sep 10 '12 at 20:37


If you'd find a database easier to work with, I'd go with that. –  eggyal Sep 9 '12 at 13:14
sure, database, unless the error is about unable to connect to a database :P –  dbf Sep 9 '12 at 13:15

4 Answers 4

Personally I would store them in a database, makes it much easier for reporting.

Now if the error itself is connecting to the database, I would log it in a file as well as alert the administrator (via email) because having the database down is probably pretty serious that needs attention ASAP.

I would design the logging system with severity level. Low severity level gets logged to database, severe logs to database, file as well as email the administrator

share|improve this answer

Personally I would write them to a file.

It seems more likely to me that the database server would fail and doesn't write the exception into the table than the file handler on the system.

Of couse if there are several error categories you're going to log and you'd like to display only one category at a time sometimes, then go with the database. It certainly can make the handling somewhat easier.

share|improve this answer
Personally I would have it log errors to a database, but if the error is having trouble connecting to the database then log to a file, as well as email the administrator because that is probably pretty serious. –  Kris Sep 9 '12 at 13:18
That sounds very elegant, yes. And if you can't even log to the file just write to the php-error-log. –  Louis Huppenbauer Sep 9 '12 at 13:19

I highly suggest that you store this in files. Just make sure that the files are not accessible via HTTP (ex: http://your.host/admin/ERRORS.txt). Place it in a folder that has an .htaccess file with "Deny From All" so that files may not be loaded through HTTP.

Then, give your admins the option to view these ERROR files by letting PHP access the file and output it.

To help your admins narrow down what error files they want to view, log errors daily in different filenames. For example: ERRORS-12-09-09.TXT (Sept 9, 2012).

share|improve this answer
Thanks! Yeah, the different error log files is a good idea! Should help keep it more organized. –  user1649448 Sep 9 '12 at 13:22

Why go to the effort of storing them in a database? Use that effort to fix them.

Use a file. That file should be decreaing in size (as you will be fixing those bugs?).

share|improve this answer
Why the downvote? –  Ed Heal Sep 9 '12 at 13:28
Errors happen; it's a fact. The ones which are easy to produce are easy to fix. The ones which generally screw us up are those that occur only once every 22nd Thursday, in summer, when the sysadmin's dog is on heat and a user clicks on "Buy", then immediately reloads the page. These are the ones you want to log, so you can find them, and fix them. PS: Downvote wasn't me :) –  Luke H Oct 12 '12 at 13:50
@LukeH - What about the errors with respect to the database (not working, table dropped by accident, password has changed by somebody etc.). Those errors will not be stored because there is a fundamental problem in the system and may end up overlooked for a period of time. Errors and exceptions within the system should be a rarity and it is worthwhile to make it easier for diagnostics to capture whatever data is required to debug. That is why I think using a file is better in this case. –  Ed Heal Oct 12 '12 at 13:57