The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 18, 2019, 12:50:01 AM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: Database error logging  (Read 2952 times)
sysbuilder
Rookie
**
Offline Offline

Posts: 17


View Profile
« on: May 05, 2008, 11:53:43 PM »

So I'm a pretty big newbie when it comes to error handling, but I'm learning. I have a basic site creator system setup right now, and I envision implementing a method of error logging where serious errors are logged into a database for me to check and address later.

I've been looking over the PHP error handling functions - in your opinion, do you think this type of database error logging could be successfully done with the function set_error_handler and a custom-made error function that connects to the database, or is there a better way to go about it?

Thanks for any insight in this matter. Smiley
Logged

No links in signatures please
DangerMouse
Expert
****
Offline Offline

Posts: 244



View Profile
« Reply #1 on: May 06, 2008, 02:36:22 AM »

You don't mention what PHP version you're running?

I'm not familiar with Set_Error_Handler(), however I've considered using a similar system with Exceptions, I've just not got around to it yet.

I'm planning on subclassing Exception and in the __Construct() method including a call to an error logging class, then backing this up with a custom exception handling (Set_Exception_Handler()) function that again calls the logging object.

DM
Logged
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #2 on: May 06, 2008, 07:16:17 AM »

using a try/except methodology will be superior because it's more common in languages today - and your experience with PHP and try/except will be roughly transportable anywhere you go.

Additionally, try/except allows you to easily build in hierarchical error handling and recovery, which would be much more difficult to consistently deploy with an error handler method.
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
sysbuilder
Rookie
**
Offline Offline

Posts: 17


View Profile
« Reply #3 on: May 06, 2008, 09:10:48 AM »

Thanks perkiset and DangerMouse, I will go the route of using exceptions and try/catch and report back on how it goes (I am using PHP 5.2.5, so it should have good support for that methodology).
Logged

No links in signatures please
DangerMouse
Expert
****
Offline Offline

Posts: 244



View Profile
« Reply #4 on: May 06, 2008, 09:28:05 AM »

Ditto Perk's comments, plus if you're particularly interested in database handling, the PDO extension makes use of exceptions (plus many other common PHP modules e.g. DOM processing).

It takes a while to get used to the method of doing things (I havent quite figured out when to use an exception and when to return a false value for example) but its great for OO code reducing the close coupling of objects.

DM
Logged
hondaman
Rookie
**
Offline Offline

Posts: 11


View Profile
« Reply #5 on: May 18, 2008, 07:41:30 PM »

I envision implementing a method of error logging where serious errors are logged into a database for me to check and address later.


What if the database goes down?  I always like this not fast
code but great for debugging monolithic 'other peoples' apps..

Down and Dirty. Ive been known to have each line as comma
seperated values so i can suck it into a db later if i HAVE to.

Code:
<?php
  logit
("program begin.");
  
//..
  //..
  
logit("right before dbconnect..");
  
$db->blahblah;
  
logit("the line right after the db did something.");

?>


<?php
  
function Logit($out)
 {
  
$dt date("Y-m-d");
  
$tm time(void);
  
  
$nuout "$dt $tm:: $out \n\r";
  
//$nuout = "$dt,$tm,$out \n\r"; 

  
file_put_contents('log.txt'$nuoutFILE_APPEND);
 
  }
?>


« Last Edit: May 18, 2008, 07:48:09 PM by hondaman » Logged

No links in signatures please
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!