2022 Developer Survey is open! Take survey.
22 votes
Accepted

How can I print out a Joomla query?

you need to echo __toString() echo($query->__toString()); you can fing more info here https://docs.joomla.org/API16:JDatabaseQuery/_toString Hope it helps
user avatar
18 votes
Accepted

Can I use PostgreSQL with Joomla 3.3

You can use it, but I would not recommend it especially if you are not familiar with Joomla's codebase and specific PostgreSQL particularities. In the last couple of months I looked into a couple of ...
user avatar
17 votes
Accepted

Method for creating a subquery using JDatabase

Yes, as far as i'm concerned, the way you built the subquery is the one adopted by the majority of joomla's extensions developers. I use that same method on some of my extensions and custom ...
user avatar
  • 186
16 votes
Accepted

How can I programmatically get the Joomla database prefix using php?

You can get the prefix using the following: For Joomla 2.5 use: $app = JFactory::getApplication(); $prefix = $app->getCfg('dbprefix'); For Joomla 3.2 use: $app = JFactory::getApplication(); $...
user avatar
  • 416
13 votes

Catching exception/error in database transaction

JError has been deprecated in J3.x, in favour of PHP exceptions, as it intermixed 2 different programming concepts: logging and error handling (the logging side has now been implemented as JLog). For ...
user avatar
  • 2,295
10 votes

Method for creating a subquery using JDatabase

AFAIK there isn't a built in way to do easy subqueries, which is probably a deficiency in the system and should be corrected via PR. However, I see no issue with your example - seems reasonable ...
user avatar
  • 1,022
9 votes
Accepted

Making Custom HTML User Profile Page by using Joomla Variables

Ok for starters, you can't use a .html site to display user information, instead you will require a .php file. Once created, you will need to import the Joomla CMS like so: define( '_JEXEC', 1 ); ...
user avatar
  • 26.4k
9 votes
Accepted

Options for backups, restoring, and staging?

The easiest way I've found is to use Akeeba Backup. Very easy to use and free.
user avatar
  • 801
9 votes

How can I print out a Joomla query?

You can also use Joomla's replacePrefix function which dumps out the query in a format that can be inserted straight into the likes of PhpMyAdmin. Here's an example: $db = JFactory::getDbo(); $...
user avatar
  • 26.4k
8 votes
Accepted

Using Separate Databases for Each Component

Storing data for each component in a different database is an extremely bad idea. Yes, it is possible with Joomla, however you should have to hack into a large amount of core files, change database ...
user avatar
  • 26.4k
8 votes
Accepted

How can I get the names of the columns in an object or table with Joomla's SQL?

Your foreach will result in situation where $key is array key and $value is one row from database. If you want to get column names from result just use get_object_vars: $db = JFactory::getDbo(); $...
user avatar
8 votes

Adding Multiple Users in Joomla

I see in the tags of your question you are using mysql and phpmyadmin, so I assume you are after a a way to INSERT records of users directly into the Joomla database. However please note that, the ...
user avatar
  • 19.5k
7 votes
Accepted

Recommended practices regarding transfering database from Joomla 1.5 to Joomla 3

What I would recommend you do is: Export the database for the Joomla 1.5 site, apart from the #__users table Install a fresh copy of Joomla 1.5 on your localhost Import the database dump you ...
user avatar
  • 26.4k
7 votes
Accepted

Table marked as crashed and repair failed

You might need to use MySQL to manually repair the table. If you can run arbitrary MySQL on your server, run the mysql CLI and use: REPAIR TABLE jos_users; Alternatively, phpMyAdmin (supplied by ...
user avatar
  • 2,295
6 votes

How to do SQL exception / error handling compatible with 2.5 and 3.x?

Pretty much the same as @ValentinDespa 's answer but i'm just gonna merge the two things together into something that will work in 2.5 and 3.x. This rather than displaying a full page error message ...
user avatar
6 votes

How to save checkbox values in a table?

@Lodder is definitely correct, but there is another syntax for those who are interested. I prefer this syntax because it saves typing the field names as many times $data = new stdClass; $input = ...
user avatar
6 votes
Accepted

Change "Show page heading" param for every menu item

I believe you'll need to use SQL statements such as below. But be CAREFUL - BACKUP THE TABLE FIRST to be sure that you can restore it if there are more considerations than you've realized at this ...
user avatar
  • 7,665
6 votes

How can I print out a Joomla query?

You can also use native dump() method: echo $query->dump();
user avatar
  • 4,045
6 votes
Accepted

Create a table observer

This was working ok on my instance Joomla 3.9.22 with PHP 7.3.5 (and mysql). Then to test this I selected PHP 7.0.33 instead and it gave me an error: Fatal error: Declaration of MyObserver::...
user avatar
6 votes

Restoring with Akeeba to a new site on cpanel

Yes you will need to enter the details for the development server database at this step. By default, Akeeba Kickstart will display the database details from the site it was backed up from... it ...
user avatar
  • 71
5 votes
Accepted

How to save checkbox values in a table?

You will first need to get the values using JInput like so, $input = JFactory::getApplication()->input; $username = $input->get('username'); $choice1 = $input->get('choice1'); $choice2 = $...
user avatar
  • 26.4k
5 votes

How can I print out a Joomla query?

The JDatabaseQuery object has a __toString() function that outputs the query so you can do: echo $db->getQuery(); Or if you want to pass it to a function you can explicitly cast it to a string ...
user avatar
  • 1,771
5 votes
Accepted

What is Joomla article options stored table?

The data you are looking for is available in same table (#__content) and you will find all the options in attribs column. Note that in MySQL the table will have the db table prefix that you have ...
user avatar
  • 1,771
5 votes
Accepted

with insert on duplicate key update - updating multiple rows at once

Building a REPLACE INTO query is just as simple as building an INSERT ... ON DUPLICATE KEY UPDATE. Note that there is a difference between REPLACE INTO AND ON DUPLICATE KEY UPDATE. Code: $columns = ...
user avatar
  • 4,403
5 votes

JFactory::getDbo() deprecated-- what's the replacement?

Joomla 3.9.x has a file public_html/libraries/classmap.php that contains all the old style Class names, and the new replacements. E.g. JLoader::registerAlias('JFactory', '\\Joomla\\CMS\\Factory', '5....
user avatar
  • 1,328
4 votes

How to do SQL exception / error handling compatible with 2.5 and 3.x?

Watch out for exposing too much info! Please note that by throwing SQL errors into the wild, you may expose your database structure or other sensitive information. I would throw SQL errors only in ...
user avatar
4 votes

How can I programmatically get the Joomla database prefix using php?

If you are accessing the Joomla DB via external scripts, maybe you don't want to initialize all joomla stuffs only to get the database prefix. So, you can require the configuration.php file inside ...
user avatar
4 votes

Recommended practices regarding transfering database from Joomla 1.5 to Joomla 3

Finally, I've done the export/import via CSV (as I also had to edit all the fulltext entries) and here are the little things that I had to search for: export the Db via CSV, then edit it with Open ...
user avatar
  • 986
4 votes
Accepted

MySQL error: Unknown storage engine 'InnoDB'

This sounds like an error with your database server rather than your website. Are you by any chance using a Hostgator Reseller account? Hostgator is currently experiencing problems with some of their ...
user avatar
  • 13.3k
4 votes
Accepted

Joomla 2.5, how to use "HAVING" using Query Object

If you are using having clause without group_by then it will act just like where clause. JDatabaseQuery class provides method for having clause. Try this $query->having('distance <=50');
user avatar
  • 1,791

Only top scored, non community-wiki answers of a minimum length are eligible