DB-QUERY-OLD-001

$db->query()

Old $db->query() API

On modern drivers, query() is not the execute API Joomla 3 tutorials taught. Use execute() for writes and load* for reads. Bind parameters instead of concatenating SQL.

$db->query()$db->execute() / loadObjectList()

Dies at Joomla 3 → 4J3: Works nativelyJ4: Changed behaviourJ6: Changed behaviourBC plugin: not applicablePatch possible — review itDatabase API

What you will see

  • Call to undefined method ...::query()
  • Database query failed

Symptoms people search

sql concat 500 · query() undefined

Replace this code

Swap $db->query() for $db->execute() / loadObjectList().

Joomla 3

Remove or stop calling this

$db->setQuery($sql);
$db->query();
$rows = $db->loadObjectList();

Joomla 4 / 6

Use this instead

$db->setQuery($query);
$db->execute();
$rows = $db->loadObjectList();

How to fix it

  1. 1Build queries with $db->getQuery(true).
  2. 2Use quoteName / bind.
  3. 3Never interpolate $_GET into SQL.

Also known as

query() · execute() · bind

Related issues

Get in touch

Have a project in mind? Let's talk about it.

Tell us what you're building. Whether it's a new site, an online store, a mobile app, or something that needs AI under the hood, we'll get back to you within a business day.

Free consultation
No commitment, no pressure
Reply within 24 hours
Usually much faster

Prefer a direct conversation?

Request a project quote

Tell us about your project

Fill out the quick form and we'll reach out.