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
LonelyProgrammer
Forum Contributor
Posts: 108 Joined: Sun Oct 12, 2003 7:10 am
Post
by LonelyProgrammer » Sun Oct 12, 2003 7:10 am
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?
JAM
DevNet Resident
Posts: 2101 Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:
Post
by JAM » Sun Oct 12, 2003 7:23 am
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;
}
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Sun Oct 12, 2003 7:50 am
JAM
DevNet Resident
Posts: 2101 Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:
Post
by JAM » Sun Oct 12, 2003 7:56 am
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 » Sun Oct 12, 2003 2:04 pm
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 » Mon Oct 13, 2003 5:42 am
The problem with those functions is I could never seem to get them to work in the event of a SQL syntax error.