note 88166 added to function.mysql-error
| From: | PendragonCastle at osu1 dot php dot net | Date: | Tue, 13 Jan 2009 15:16:19 +0000 |
| Subject: | note 88166 added to function.mysql-error | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-149143@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().
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);
----
Server IP: 208.69.120.35
Probable Submitter: 70.142.45.111
----
Manual Page -- http://www.php.net/manual/en/function.mysql-error.php
Edit -- https://master.php.net/note/edit/88166
Del: integrated -- https://master.php.net/note/delete/88166/integrated
Del: useless -- https://master.php.net/note/delete/88166/useless
Del: bad code -- https://master.php.net/note/delete/88166/bad+code
Del: spam -- https://master.php.net/note/delete/88166/spam
Del: non-english -- https://master.php.net/note/delete/88166/non-english
Del: in docs -- https://master.php.net/note/delete/88166/in+docs
Del: other reasons-- https://master.php.net/note/delete/88166
Reject -- https://master.php.net/note/reject/88166
Search -- https://master.php.net/manage/user-notes.php