{{ tables.sqlselect }} – SQL SELECT Query

Allows execution of custom SELECT queries.

This feature is intended for advanced users only.
A dedicated READ-ONLY MySQL database user must be configured in Joomla configuration.php.
UPDATE, DELETE, INSERT and other write operations are not supported.”

Basic usage:

{{ tables.sqlselect('SELECT COUNT(id) FROM #__users','scalar') }}

Select user purchases using current user ID:

{{ tables.sqlselect('SELECT * FROM #__customtables_table_purchases WHERE ct_userid = ' ~ (user.id) ~ ' LIMIT 100') | json_encode }}

 Looping over query results:

{% set purchases = tables.sqlselect('SELECT ct_title, ct_price FROM #__customtables_table_purchases WHERE ct_userid = ' ~ user.id ~ ' LIMIT 10') %}

{% for purchase in purchases %}
    Title: {{ purchase.ct_title }}<br/>
    Price: {{ purchase.ct_price }}<br/><br/>
{% else %}
    No purchases found.
{% endfor %}

Parameters:

  1. Query
  2. Result Mode (optional) – auto, scalar (Single value), row (Single row), list (Multiple rows)


This functionality requires a separate MySQL user with read-only privileges.
The database user credentials must be added to your Joomla configuration.php file as shown below:

// Custom Tables – READ ONLY DB user
public $ct_readonly_db_user = 'joe_can_read';
public $ct_readonly_db_pass = 'strong-password';
public $ct_readonly_db_name = 'joomla_db';
public $ct_readonly_db_host = 'localhost';

Note: This read-only user ensures that queries executed via the {{ tables.sqlselect() }} tag cannot modify the database. Always use a dedicated read-only user for security and stability.


What are your feelings

Leave a Reply

Updated on February 15, 2026