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()
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
- 1Build queries with $db->getQuery(true).
- 2Use quoteName / bind.
- 3Never interpolate $_GET into SQL.
Also known as
query() · execute() · bind
Related issues
- Joomla 5 → 6Database API
Factory::getDbo() / getDBO()
JFactory::getDbo() → $this->getDatabase() or Factory::getContainer()->get(DatabaseInterface::class)
- Joomla 3 → 4Manifest / installer
_QQ_ language placeholder
_QQ_ → Escaped quotes in INI files
- Joomla 3 → 4Database API
String-concat SQL instead of bind()
$db->setQuery('SELECT * FROM #__lms WHERE id = ' . $id) → $query->bind() / quoteName + bind
- Joomla 5 → 6Database API
JDatabaseDriver class name
JDatabaseDriver → Joomla\Database\DatabaseDriver
- Joomla 5 → 6Database API
JDatabaseQuery class name
JDatabaseQuery → Joomla\Database\DatabaseQuery
- Joomla 5 → 6Database API
JDatabase class name
JDatabase → Joomla\Database\DatabaseDriver