Welcome to WebmasterWorld Guest from 54.224.103.186

Forum Moderators: open

Message Too Old, No Replies

How do I get the last mysql query that was executed

     
6:11 pm on Jan 18, 2007 (gmt 0)

Junior Member

10+ Year Member

joined:Apr 26, 2004
posts:137
votes: 0


In brief, I want to find out the last SQL statement that was executed (when there's an error) and log it.

I get the last error in with with mysql_error, is there a similar command for the last query?

Regards,

Jez.

3:51 pm on Jan 19, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member eelixduppy is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Nov 12, 2005
posts:5966
votes: 0


Are you talking about PHP? There is no function that returns the last query, but what you can do is store the query in a variable, and conditionally test to see if the query went through successfully. If it did not, then produce an error and log it.

$query = "INSERT INTO tablename (col1, col2) VALUES ('moo','fish')";
$result = mysql_query($query);
if(!$result) {
echo 'An error has occured!";
//log error with $query
exit()
}

I hope this helps! :)

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members