Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

inserting php errors into mysql 1

Status
Not open for further replies.

pushyr

Programmer
Jul 2, 2007
159
GB
just a quickie...

i get this php error and would like to know if it's possible to insert such an error into mysql?

Code:
Warning: fopen([URL unfurl="true"]http://www.mysite.com)[/URL] [function.fopen]: failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request in /file/script/index.php on line 739
cannot open file
 
yes.
create a table for the following fields and then use this script
Code:
create table errorTable (
errorID int(10) auto_increment primary key,
errno int(5),
errstr varchar (255),
errfile varchar (255),
errline int (6)
)

Code:
<?php
set_error_handler('myErrorHandler', E_WARNING | E_NOTICE );

function myErrorHandler ($errno, $errstr, $errfile, $errline, $errcontext) {
	//assume database connection string and suitable table
	
	//insert into database
	$query = "Insert into errorTable (eventID, errorno, errstr,errfile, errline) values (null, '%s', '%s', '%s', '%s')";
	$result = @mysql_query (sprintf(	$query, 
								$errno, 
								mysql_real_escape_string($errorstr), 
								mysql_real_escape_string($errfile), 
								$errline));
	if (!$result) {echo 'db write went wrong. ' . mysql_error();}
	//say whatever you want about the error
	//and exit if you want to
	return false; //to populate php_error_msg
}
?>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top