How to check errors of a mysql_query?

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
mischievous
Forum Commoner
Posts: 71
Joined: Sun Apr 19, 2009 8:59 pm

How to check errors of a mysql_query?

Post by mischievous »

I need to be able to check if the mysql_query($query) has any errors in it?

How do i display this?

Im trying to do an insert and its not inserting into mysql for some reason? was just working fine a couple minutes ago, now its not working at all?
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: How to check errors of a mysql_query?

Post by jackpf »

put "or die(mysql_error());" after the query...
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: How to check errors of a mysql_query?

Post by superdezign »

Yes, mysql_error() is the function you are interested in.
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: How to check errors of a mysql_query?

Post by Darhazer »

jackpf wrote:put "or die(mysql_error());" after the query...
Not always failed query means end of script execution, maybe just rolling back the transaction?
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: How to check errors of a mysql_query?

Post by jackpf »

Yeah I know.

But...he said he wanted to check why a query was failing. That's the quickest way imo. :)
User avatar
Mirge
Forum Contributor
Posts: 298
Joined: Thu Sep 03, 2009 11:39 pm

Re: How to check errors of a mysql_query?

Post by Mirge »

jackpf wrote:Yeah I know.

But...he said he wanted to check why a query was failing. That's the quickest way imo. :)
+1 :!:
Post Reply