Errors from database.php on simple mysql field increment

Have a programming question regarding your component, plug-in, extension or core hacks? Have an interesting tidbit, FAQ or programming tip you’d like to share? This is the place for you.

Moderators: tjay, seadap, Rogue4ngel, matthewhayashida

Post Reply
User avatar
PerroLoco
Joomla! Apprentice
Joomla! Apprentice
Posts: 5
Joined: Fri Dec 29, 2006 4:34 pm
Location: Colorado western slope
Contact:

Errors from database.php on simple mysql field increment

Post by PerroLoco » Fri Feb 01, 2008 4:58 pm

Hi.

I've been working on a custom component, and it's been a lot of fun learning all about Joomla!'s API and generally making things happen. But today I hit a snag I'm not sure how to get around.

In my component, when a user answers a question correctly, I want to increment the value of a field in the DB. I'm using the following code:

Code: Select all

$database->setQuery("UPDATE table SET num_correct_answers = num_correct_answers + 1 WHERE quiz_id = $qid");
$result = $database -> loadObjectList();
	if ($database -> getErrorNum()) {
		echo $database -> stderr();
		return false;
	}
I'm no mysql expert, but I've read multiple other posts out there in the world about this being the easiest way to increment the value without multiple calls to the DB.

And while this appears to be working (the value is being increased every time), Joomla! is giving me a couple warning messages from database.php.
Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in [path]/includes/database.php on line 489

Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in [path]/includes/database.php on line 496
Is this because I'm doing something wrong, or because there is an incompatibility with this statement and what database.php expects? Your wisdom is greatly appreciated.

Running Joomla! 1.0.12
PHP 4 and MySQL 5

M
Last edited by PerroLoco on Fri Feb 01, 2008 11:34 pm, edited 1 time in total.

User avatar
PerroLoco
Joomla! Apprentice
Joomla! Apprentice
Posts: 5
Joined: Fri Dec 29, 2006 4:34 pm
Location: Colorado western slope
Contact:

Re: Errors from database.php on simple mysql field increment

Post by PerroLoco » Fri Feb 01, 2008 11:33 pm

I was able to answer my own question when I found this post:

http://forum.joomla.org/index.php?topic=248785.msg1141396

As it turns out, you need different $database code when making UPDATE, INSERT, or DELETE sql statements.

I hope this helps the next person scratching their head about it!


Post Reply