0

I am new to joomla and I want to create a table in joomla database manually with the data and get those details to an article in joomla. Before that as my knowledge we need to get the database connection to a connection variable. I searched in the locally installed Joomla directory to find a file containing the database connection code base. I want to know is there a way to get the connection into a separate variable as follows

enter image description here

  • I’m glad that you have a purpose now in life, but please include your code samples what you already tried to achieve the goal and point where exaclty you are stuck with it. You are on stackexchange now. – Zollie Jan 17 at 6:38
  • @Zollie I have updated the question. – Shan Chathusanda Jayathilaka Jan 17 at 8:41
  • Then you got two nice, useful answer. This is how it works. Review them and with clicking on the tick at the top left side of the answer you can accept the most helpful and useful. Or leave the replyers a comment on their answer if you need more clarification on the answer. This way you can help the volunteers and yourself too. Thank you and welcome on Joomla stackexchange! – Zollie Jan 17 at 19:23
  • 1
    @Zollie got your point with full respect. – Shan Chathusanda Jayathilaka Jan 17 at 19:29
3

To get started with querying the Joomla way, you'll need a database connection object. All the heavy lifting is already done for you.

$db = JFactory::getDbo();

Using this object, there is a sea of methods that can be chained to it.

Normally, the next step will be to declare a new query object. This object also has many methods which allow you build a valid mysql query.

$query = $db->getQuery(true);

After this, you'll need to see the documentation about how to convert raw mysql syntax to Joomla's query building syntax.

https://docs.joomla.org/Inserting,_Updating_and_Removing_data_using_JDatabase

To give you a pool of working snippets with explanation and error reporting, search this site for my answers to mysql questions. All of my answers are tested to be correct, unless I express in the post that my snippet is untested

https://joomla.stackexchange.com/search?q=user%3A12352+%5Bmysql%5D

I am confident that my answers will help you to find clarity.

2

To achieve what you want in Joomla! way, you need to develop/create a Joomla! content plugin, Joomla! documentation is excellent guide to complete this step: https://docs.joomla.org/J3.x:Creating_a_content_plugin

Then, you need to know how to select data from database tables, also Joomla! documentation has a good tutorial to read in this context: https://docs.joomla.org/Selecting_data_using_JDatabase

  • I have completed the task only by using the second step. Is it necessary to do the first step as well because from the second step I completed my task. – Shan Chathusanda Jayathilaka Jan 19 at 10:31
  • It is necessary to have a reusable and permanent solution, most probably you have hacked a Joomla or another extension file, where all changes will be lost on the first Joomla/Extension update. – Mohamed Abdelaziz Jan 19 at 13:19
  • Got your point. – Shan Chathusanda Jayathilaka Jan 19 at 16:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.