Perform a Mysql Query using Joomla!

0 min read 92 words

This is really actually meant for future reference for myself as lately I’ve been doing quite a lot of Joomla! mysql coding and have used the following code just short of 3million times.

$db = JFactory::getDbo();
$querySelectId = "SELECT `id` FROM #__some_table WHERE `user_id`='$user_id'";
$db->setQuery($querySelectId);
$db->query();
$data = $db->loadAssoc();

What we do in the above code snippet is select a user_id from some_table (#__) is short for whatever your database table’s prefix is (Joomla! replaces this itself) and then we perform the query and return the row’s `id` into the $data variable.

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