0

I've come across this error when performing some database queries in my J4 site model:

    $db->setQuery((string)$query);

    try {
        $rows = $db->loadObjectList();
    } catch (RuntimeException $e) {
        Factory::getApplication()->enqueueMessage($e->getMessage(),'danger');
        return false;
    }

Then I do some stuff with the output called $rows and then based on the result of this "stuff" (ie a ref_id) I try to update all the records that were returned in $rows using:

        $db     = Factory::getContainer()->get('DatabaseDriver');
        $query  = $db->getQuery(true);
        $query->clear();
        $query = ' UPDATE #__my_table_name SET state = 5, ref_id = '.(int) $ref_id.' WHERE user_id = '.(int) $user->id.' AND state = 1 ';
        $db->setQuery((string)$query);

        try {
            $result = $db->loadResult();
            return true;
        } catch (RuntimeException $e) {
            Factory::getApplication()->enqueueMessage($e->getMessage(),'danger');
            return false;
        }

The "stuff" being done has nothing to do with the database, just tweeking some text files, so why is it saying I'm out of sync? Is there a new step required here? Any and all help greatly appreciated. Cheers.

3
  • 1
    After your UPDATE query, I think you need to replace $result = $db->loadResult(); with $result = $db->execute();
    – Lodder
    Nov 30, 2021 at 6:04
  • Ahhh, of course, as I don't really need the result a straight execute does the trick, thanks. Nov 30, 2021 at 6:10
  • You're welcome. Feel free to post as a proper answer below and mark as accepted so other know the issue has been solved.
    – Lodder
    Nov 30, 2021 at 6:13

1 Answer 1

1

As recommended by @Lodder changing:

$db->loadResult();

to

$db->execute();

solved the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.