Post by furrywombat » Thu Mar 27, 2014 8:43 pm

Working on a custom extension for our site and noticed that there does not appear to be any method of checking for MySQL INSERT errors. If the insert query produces an error, it just stops. Is there any way to utilize $this->db->query in such a way that rather than choking, an error message is produced allowing the insert query to be ignored and error message returned for debugging purposes?

User avatar
New member

Posts

Joined
Sat Oct 19, 2013 9:15 pm
Location - Chair

Post by furrywombat » Fri Apr 04, 2014 7:16 am

Anyone? Seems like there really should be a method for this...

User avatar
New member

Posts

Joined
Sat Oct 19, 2013 9:15 pm
Location - Chair

Post by Qphoria » Wed Apr 09, 2014 10:51 pm

Be sure you have error logging enabled. By default you should get an error that explains the issue
Example:
http://forum.opencart.com/viewtopic.php?t=50292#p238419

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by furrywombat » Thu Apr 10, 2014 1:45 am

Thanks Q. We have the log available for review after the fact but wondering if there is an error checking system (existing or add-on?) that would allow the error to be bypassed, for example:

if ( $query->error = "ABC"), $this->emailAdmin("Error Detail"), perform alternate action... else, proceed as planned, etc, etc;

Is this something that OpenCart is capable of doing?

User avatar
New member

Posts

Joined
Sat Oct 19, 2013 9:15 pm
Location - Chair

Post by rph » Thu Apr 10, 2014 4:52 am

You can certainly modify the database drivers to do it but it's not a default feature. Is there a reason you can't use specific queries/return results?

-Ryan


rph
Expert Member

Posts

Joined
Fri Jan 08, 2010 5:05 am
Location - Lincoln, Nebraska

Post by furrywombat » Thu Apr 10, 2014 4:58 am

UPDATE & SELECT queries offer this feature as $query->error but INSERT queries do not. The whole function just chokes when an INSERT query fails, but when an UPDATE or SELECT query fails the error is produced as an object.

Why not with the INSERT queries?

User avatar
New member

Posts

Joined
Sat Oct 19, 2013 9:15 pm
Location - Chair

Post by rph » Thu Apr 10, 2014 5:18 am

furrywombat wrote:UPDATE & SELECT queries offer this feature as $query->error but INSERT queries do not. The whole function just chokes when an INSERT query fails, but when an UPDATE or SELECT query fails the error is produced as an object.
Not sure where you're getting your info from but it's not accurate for a default install. The only values that are returned for db::query are bool true (e.g. INSERT, UPDATE) or an object with properties row, rows, and num_rows (e.g. SELECT).

-Ryan


rph
Expert Member

Posts

Joined
Fri Jan 08, 2010 5:05 am
Location - Lincoln, Nebraska

Post by furrywombat » Thu Apr 10, 2014 5:44 am

You're right... I was thinking of something else for the ->error object, however, what would cause an INSERT/UPDATE error to choke a function rather than simply returning true/false?

User avatar
New member

Posts

Joined
Sat Oct 19, 2013 9:15 pm
Location - Chair

Post by rph » Thu Apr 10, 2014 6:50 am

Depends on the driver. For MySQLi it's when an error code is returned. For MySQL it's when bool false is returned.

-Ryan


rph
Expert Member

Posts

Joined
Fri Jan 08, 2010 5:05 am
Location - Lincoln, Nebraska

Post by furrywombat » Thu Apr 10, 2014 8:19 pm

Sounds like it's time to upgrade to MySQLi. Thanks for the assistance.

User avatar
New member

Posts

Joined
Sat Oct 19, 2013 9:15 pm
Location - Chair
Who is online

Users browsing this forum: Bing [Bot] and 22 guests