How do I query a database?
XOOPS has a database abstraction layer for you to use, when accessing the database.
The database object can be retrieved in two ways:
a) using the $xoopsDB instance - if you are in a function or class method, you will need to declare it global first with
global $xoopsDB;
$xoopsDB =& XoopsDatabaseFactory::getDatabaseConnection();
//Any statement goes in the query - SELECT, UPDATE, INSERT etc.
$result = $xoopsDB->query('SELECT * FROM [...] ');
// if it is a SELECT statement, $result will now be a resultset so let's loop through it
while ($row = $xoopsDB->fetchArray($result)) {
$variable = $row['index'];
$another_variable = $row['another_index'];
}
This Q&A was found on XOOPS Web Application System : https://xoops.org/modules/smartfaq/faq.php?faqid=192