Error reporting function?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
LonelyProgrammer
Forum Contributor
Posts: 108
Joined: Sun Oct 12, 2003 7:10 am

Error reporting function?

Post 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?
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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;
}
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

maybe some of the magic constants are of interest
http://www.php.net/manual/en/language.c ... efined.php
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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();
?>
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post 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?
LonelyProgrammer
Forum Contributor
Posts: 108
Joined: Sun Oct 12, 2003 7:10 am

Post 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.
Post Reply