Page 1 of 1

Error reporting function?

Posted: Sun Oct 12, 2003 7:10 am
by LonelyProgrammer
Hi all,

Currently I am have been doing my sql error reporting like this:

Code: Select all

$sql = "SELECT blah FROM blahblah WHERE blahblahblah..."

if (! mysql_query($sql)) die ("SQL statement ї $sql ] failed in function mySQL);
I thought of having a function like:

Code: Select all

if (! mysql_query($sql) die (reportSQLError());
But I have no idea on how to get the name of the function where the error occured. Any idea?

Posted: Sun Oct 12, 2003 7:23 am
by JAM
I dont think there is something that will help you.
You might however use something like this, and manually write the names of them (in this example, thisfunction).

Code: Select all

reportSQLError('thisfunction');
function reportSQLError($name) {
 echo 'Error in: '.$name;
}

Posted: Sun Oct 12, 2003 7:50 am
by volka
maybe some of the magic constants are of interest
http://www.php.net/manual/en/language.c ... efined.php

Posted: Sun Oct 12, 2003 7:56 am
by JAM
I really missed that one. =)

Code: Select all

<?php
function foo($name) {
    return 'Error in: '.$name;
}
function bar() {
    if (1) {
        echo foo(__FUNCTION__);
    }
}
bar();
?>

Posted: Sun Oct 12, 2003 2:04 pm
by m3rajk
this returns the error number: mysql_errno($database_connection);

this returns the error: mysql_error($database_connection);

use them and make the function or what not.

maybe just use them?

Posted: Mon Oct 13, 2003 5:42 am
by LonelyProgrammer
The problem with those functions is I could never seem to get them to work in the event of a SQL syntax error.