note 88166 modified in function.mysql-error by danbrown
| From: | danbrown@php.net | Date: | Wed, 14 Jan 2009 01:05:36 +0000 |
| Subject: | note 88166 modified in function.mysql-error by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-149163@lists.php.net to get a copy of this message | ||
Using a manipulation of josh ><>'s function, I created the following. It's
purpose is to use the DB to store errors. It handles both original query, as well as the error log.
Included Larry Ullman's escape_data() as well since I use it in q().
<?php
function escape_data($data){
global $dbc;
if(ini_get('magic_quotes_gpc')){
$data=stripslashes($data);
}
return mysql_real_escape_string(trim($data),$dbc);
}
function q($page,$query){
// $page
$result = mysql_query($query);
if (mysql_errno()) {
$error = "MySQL error ".mysql_errno().":
".mysql_error()."\n<br>When executing:<br>\n$query\n<br>";
$log = mysql_query("INSERT INTO db_errors (error_page,error_text) VALUES
('$page','".escape_data($error)."')");
}
}
// Run the query using q()
$query = "INSERT INTO names (first, last) VALUES ('myfirst',
'mylast'");
$result = q("Sample Page Title",$query);
?>
--was--
Using a manipulation of josh ><>'s function, I created the following. It's
purpose is to use the DB to store errors. It handles both original query, as well as the error log.
Included Larry Ullman's escape_data() as well since I use it in q().
function escape_data($data){
global $dbc;
if(ini_get('magic_quotes_gpc')){
$data=stripslashes($data);
}
return mysql_real_escape_string(trim($data),$dbc);
}
function q($page,$query){
// $page
$result = mysql_query($query);
if (mysql_errno()) {
$error = "MySQL error ".mysql_errno().":
".mysql_error()."\n<br>When executing:<br>\n$query\n<br>";
$log = mysql_query("INSERT INTO db_errors (error_page,error_text) VALUES
('$page','".escape_data($error)."')");
}
}
// Run the query using q()
$query = "INSERT INTO names (first, last) VALUES ('myfirst',
'mylast'");
$result = q("Sample Page Title",$query);
http://php.net/manual/en/function.mysql-error.php