Custom Query with Joomla

Custom Query with Joomla
Share: Share on Facebook1Share on LinkedIn4Tweet about this on Twitter0Share on Google+0Share on Reddit0Buffer this pageDigg thisEmail this to someoneShare on StumbleUpon0Share on TumblrPin on Pinterest0Print this page

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.

Share: Share on Facebook1Share on LinkedIn4Tweet about this on Twitter0Share on Google+0Share on Reddit0Buffer this pageDigg thisEmail this to someoneShare on StumbleUpon0Share on TumblrPin on Pinterest0Print this page

2 thoughts on “Custom Query with Joomla”

  1. Hi, I would be curious whether SQL injection is an issue here or not?

    1. JDatabaseQuery class automatically filters the input so query is sql injection safe.

Leave a Reply

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

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=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

Most Popular Posts

GoTo statement in PHP

Posted on 3 years ago

Bhumi

Table layout using DIV tags

Posted on 2 years ago

Bhumi

Mysql String Function FIND_IN_SET( )

Posted on 3 years ago

Bhumi

Post via e-mail in WordPress

Posted on 3 years ago

Bhumi

New Features in MySQL 5.6

Posted on 3 years ago

Bhumi