SQL-BIND-001
$db->setQuery('SELECT * FROM #__lms WHERE id = ' . $id)
String-concat SQL instead of bind()
Concat still “works”. It is SQL injection with extra steps. Joomla 4+ query objects support bind(). Migrations should stop interpolating.
$db->setQuery('SELECT * FROM #__lms WHERE id = ' . $id) → $query->bind() / quoteName + bind
Symptoms people search
sql injection · setQuery concat · bind parameters
Replace this code
Swap $db->setQuery('SELECT * FROM #__lms WHERE id = ' . $id) for $query->bind() / quoteName + bind.
Joomla 3
Remove or stop calling this
$db->setQuery('SELECT * FROM #__lms WHERE id = ' . (int) $id);Joomla 4 / 6
Use this instead
$query = $db->getQuery(true)
->select('*')
->from($db->quoteName('#__lms'))
->where($db->quoteName('id') . ' = :id')
->bind(':id', $id, ParameterType::INTEGER);
$db->setQuery($query);How to fix it
- 1Use getQuery(true), quoteName, and bind().
- 2Never setQuery() a string built from request data.
Also known as
bind() · quoteName · setQuery · #__
Related issues
- Joomla 5 → 6Database API
Factory::getDbo() / getDBO()
JFactory::getDbo() → $this->getDatabase() or Factory::getContainer()->get(DatabaseInterface::class)
- Joomla 3 → 4Database API
Old $db->query() API
$db->query() → $db->execute() / loadObjectList()
- Joomla 3 → 4Manifest / installer
_QQ_ language placeholder
_QQ_ → Escaped quotes in INI files
- 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