homepage Welcome to WebmasterWorld Guest from 54.226.10.234
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderator: open

Databases Forum

    
How do I get the last mysql query that was executed
jezzer300

10+ Year Member



 
Msg#: 3223928 posted 6:11 pm on Jan 18, 2007 (gmt 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.

 

eelixduppy

WebmasterWorld Senior Member eelixduppy us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 3223928 posted 3:51 pm on Jan 19, 2007 (gmt 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! :)

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved