|
Posted by J.O. Aho on 11/07/06 13:55
nawfer wrote:
> IfI want to use a query
> SELECT ID
> FROM table;
>
> 1) what code to use for verify if there is or not the table?
Assuming you are using mysql as your database, if not, just look a similar
function for your database.
$query="SELECT * FROM table";
/* We suppress output to the html, in case we haven't set a logfile usage */
if(!@mysql_query($query)) {
/* there was some error, we just type it out and exit the script */
echo mysql_error();
exit;
}
> 2) what is the better solution for manage error:
> @query=...
> A- so I not have any error at video an the code however it continues?
The @ is useful if you can get errors that aren't fatal or if you want to make
your own error reporting system. No matter if you use @ or not, you should
always check the values that gets returned from a function.
> B- is possible to register the error @ in a file?
If you want to use a logfile or/and disable error output, then go to your
php.ini and edit
error_reporting - for how verbose reporting you want
display_errors - should the errors be outputted to stdout
log_errors - should a logfile be used
error_log - where to log the errors (logfile name)
> C- is this the better solution respect at 1, because 1
> some slows down the code (it must verify every time if table is there
> or not) ?
Even if it slows down things a little bit (don't think you will manage to
notice the difference if you write a ok "exception" handler), your script will
work better if you do check up for errors.
//Aho
[Back to original message]
|