note 99061 added to function.die
| From: | admin at studio-gepard dot pl | Date: | Sun, 25 Jul 2010 13:23:21 +0000 |
| Subject: | note 99061 added to function.die | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-171114@lists.php.net to get a copy of this message | ||
Example of PHP function with SELECT query using.
It simplifies usage of SQL and makes code much much cleaner. (similar functions can be made for
other queries)
<?php
define("sql_error_reporting",true); //true to display errors, false to hide them
function SQLselect ($TABLE,$WHERE){
if (empty($WHERE)){
$sql = "SELECT * FROM
$TABLE";
}else{
$sql = "SELECT * FROM $TABLE WHERE $WHERE";
}
$query=mysql_query($sql);
if ($query===false){ if (sql_error_reporting) {
die ("Sql error of <b>".$_SERVER["SCRIPT_NAME"]."</b>. Call to
$TABLE in ".__FILE__." on line:
".__LINE__."<br>".mysql_error()."<br><b>SQL:</b><br>$sql<br>");
}else{ die(); } }
return mysql_fetch_array($query);
}
?>
What this function does is taking the table and your query, execute the mysql query and provide the
result. If error happen during the query, than provide detailed output using code provided by
matthias dot schniedermeyer at telefonica dot de
---
Usage:
$id=1;
$result = SQLselect ("pages","id='$id'");
---
Error output example:
Sql error of /website/index.php. Call to pages in C:\www\website\functions\sql.inc on
line: 43
Unknown column 'id' in 'where clause'
SQL:
SELECT * FROM pages WHERE id='1'
----
Server IP: 82.177.164.100
Probable Submitter: 83.26.175.43
----
Manual Page -- http://www.php.net/manual/en/function.die.php
Edit -- https://master.php.net/note/edit/99061
Del: integrated -- https://master.php.net/note/delete/99061/integrated
Del: useless -- https://master.php.net/note/delete/99061/useless
Del: bad code -- https://master.php.net/note/delete/99061/bad+code
Del: spam -- https://master.php.net/note/delete/99061/spam
Del: non-english -- https://master.php.net/note/delete/99061/non-english
Del: in docs -- https://master.php.net/note/delete/99061/in+docs
Del: other reasons-- https://master.php.net/note/delete/99061
Reject -- https://master.php.net/note/reject/99061
Search -- https://master.php.net/manage/user-notes.php