note 107290 added to language.constants.predefined
| From: | akamatakamengdorcom | Date: | Fri, 27 Jan 2012 20:54:00 +0000 |
| Subject: | note 107290 added to language.constants.predefined | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-185769@lists.php.net to get a copy of this message | ||
Using magic constants (__FILE__ and __LINE__) are very useful for debugging reasons.
<?php
function do_query($query, $file, $line){
if(!empty($query){
//mysql_query() is native PHP function
$querystatus = mysql_query($query);
if($querystatus){
return true;
}else{
//we can now save the error log in the log file
//assumin that the log file located in logs/mysql.log
// another way to call error_log():
$error_message = "
File: $file
Line: $line
Detail: ".mysql_error()."
Date: ".date("Y-m-d H:i:s")."
";
//error_log is native PHP function
error_log($error_message, 3, "logs/mysql.log");
return false;
}
}else{
return false;
}
}
/*
Using:
*/
$sql = "SELECT * FROM tbl_table";
$query = do_query($sql, __FILE__, __LINE__);
if($query){
//continue to fetch results
}else{
//you can show your custom error here
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 95.154.230.254
----
Manual Page -- http://www.php.net/manual/en/language.constants.predefined.php
Edit -- https://master.php.net/note/edit/107290
Del: integrated -- https://master.php.net/note/delete/107290/integrated
Del: useless -- https://master.php.net/note/delete/107290/useless
Del: bad code -- https://master.php.net/note/delete/107290/bad+code
Del: spam -- https://master.php.net/note/delete/107290/spam
Del: non-english -- https://master.php.net/note/delete/107290/non-english
Del: in docs -- https://master.php.net/note/delete/107290/in+docs
Del: other reasons-- https://master.php.net/note/delete/107290
Reject -- https://master.php.net/note/reject/107290
Search -- https://master.php.net/manage/user-notes.php