Let Joomla and MySQL interact!

0 min read 112 words

I often need a quick and easy few lines to retrieve some data from MySQL using Joomla without all the MVC nonsense that usually goes about this topic.

So here is how I do it!

$dbSEL = JFactory::getDbo();
$dbSEL->setQuery("SELECT MAX(`start_price`) FROM #__some_table");
$dbSEL->query();
echo $dbSEL->fetchRow();

As you can see above, we get the current database object and then run a query on it.
You may notice the hash (#) in the SQL statement of this example, Joomla replaces that (as well as the underscores (__) with the database prefix which is configured, so on shared nodes you don’t have to type all that extra stuff that will need to be changed later.

Tags:
Andrew
Andrew

Andrew is a visionary software engineer and DevOps expert with a proven track record of delivering cutting-edge solutions that drive innovation at Ataiva.com. As a leader on numerous high-profile projects, Andrew brings his exceptional technical expertise and collaborative leadership skills to the table, fostering a culture of agility and excellence within the team. With a passion for architecting scalable systems, automating workflows, and empowering teams, Andrew is a sought-after authority in the field of software development and DevOps.

Tags