Custom Query with Joomla

by Bhumi // Mar 27,2013 // 2 comments

Custom Query with Joomla

Joomla is an open source content Management System.Sometimes,we are working on some customization in an existing functionality and database.so for that it is necessory to write custom queries into Joomla.

Joomla provides JDatabase class to execute joomla database. joomla 2.5 has introduced the JDatabaseQuery class concept.

Let’s understand the custom queries.Here I am going to start with select query

SELECT a records

Here,getDBO is for the connection to the global database which creates global database object if not exists.setQuery method sets the SQL query for later execution.For listing a fields,I have used loadObjectList method which returns list of fields into Object form but Joomla has various methods to fetch records and its depending on what format of data you want. so Let’s take a look into it.

1. loadResult

returns the first column from a row or a single specified column similar to the MySQL function “mysql_fetch_row()” if you specify a single column.

2. loadResultArray

returns an array of single field results into an array.

3. loadAssoc

returns an associative array of the first row.

4. loadAssocList

returns an array of the resultset rows in an associative array

5. loadRow

returns the first row returned by the query in an numeric array.

6. loadRowList

returns a list of database rows in an numeric array.

7. loadObject

returns the first row of a query into an object.

8. loadObjectList

returns a list of database objects.

9. loadNextObject

returns the next row returned by the query.

8. loadNextRow

returns the next row returned by the query.

INSERT a record

After fetching a rows from database, let’s see how to insert records into database.

To get the last inserted id,you can use following code:

UPDATE a record

Joomla provides methods for building update queries.update method generate exception if record is not exists or fail to update.

DELETE a record

As like Joomla have select, insert and update method calls, there is also a delete method for deleting records from the database.

COMMON query

This is for executing any query, even for join and other complex query, you can manage simply using below line of code.

As always thank you for reading and feel free to share your thoughts! Don’t Forget to Follow us on Twitter or Subscribe us to Get the Latest Updates.

Feedback 2

Leave a Reply

Your email address will not be published. Required fields are marked *


2 × = fourteen

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">