Joomla DB where statement not works as expected

Joomla Asked on September 5, 2021

I don’t understand the world right now. I try to make a simple query from the DB, but it fails with the message that the column is not known. I do not understand why Joomla! tries to see the value I am looking for as a column. This is my query:

            $data = new stdClass();
            $db = JFactory::getDbo();
            $query = $db->getQuery(true);
                $query->where($db->quoteName('element') . " = " . $db->quoteName('com_componentname'));
            $data->params = $db->loadObject();

        }catch(Exception $e){
            $data->query = $query->dump();
            $data->errormsg = $e->getMessage();

        return $data;

        return false;

The response is:

'errormsg' => 'Unknown column 'com_componentname' in 'where clause'',

Why does Joomla! try to find the component name as a column? What I want:
Where componentname in Columns name from table extensions.

Or is there another / better way to load the parameters of a component within a module?

One Answer

JDatabaseDriver::quoteName() is for quoting SQL identifiers. Use JDatabaseDriver:quote() to quote and escape strings.

$query->where($db->quoteName('element') . ' = ' . $db->quote('com_componentname'));

Correct answer by Sharky on September 5, 2021

Add your own answers!

Related Questions

Add field to menu settings to output open graph image

1  Asked on December 30, 2021 by mano-meter


Edited css not updated in XAMPP

1  Asked on December 9, 2021 by advait-varma


Update from 3.9.x to 4.x

2  Asked on November 27, 2021 by lovntola


Other files overriding my template css with bootstrap?

1  Asked on November 19, 2021 by matthiasdunkel


Javascript accordion with anchors for joomla

1  Asked on November 5, 2021 by fruit_alchemist


Cannot Connect To MSSQL Server

3  Asked on September 5, 2021 by jamesmandatory


PlotALOT RSForm Query showing only one result

1  Asked on September 5, 2021 by gart


Getting module parameters in AJAX call using module id

1  Asked on September 5, 2021 by user1616338


Pop up AcyMailing subscription form

1  Asked on September 5, 2021 by ygiorgos


Override 3d party extension plugin method

0  Asked on September 5, 2021 by dmitry-zar


Ask a Question

Get help from others!

© 2023 All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP