Using Joomla DatabaseQuery completion

PhpStorm can understand the DatabaseQuery builder when a database connection has been setup as described in the Setting up data source using the Joomla configuration blog. This will enable PhpStorm to auto-complete when you are building queries.

Using the database connection

Now that PhpStorm knows your database it can even do more. You can directly jump from your query to the table or field using CTRL-B / CMD-B. Let's take a look at this query from the Banners component.

$query = $db->getQuery(true)->select('MAX(ordering) as ' . $db->quoteName('max') . ', catid')

When the cursor is on the catid after the select and you hit CTRL-B / CMD-B the cursor will jump to the Database sidebar and select the catid field in the banners table.

Banners field jump

 Auto-completion while building a query

Not only can PhpStorm jump to the database table and fields but also auto-complete while you are typing the query. As shown in the screenshot below, the word cat has been typed and the options given are shown in the popup. The matches are shown in purple in this case. Select the catid from the list and hit Enter and the name is completed. Also tables are suggested that match what has been typed. After a table has been selected a new popup will come with all the fields in the just selected table which will be filtered as you continue typing.

Database query completion

Executing a query

A query can also be executed from the code by hitting CTRL-Enter / CMD-Enter, assuming that the query is executable. In case a query cannot be executed or generates an error the error message is shown in a red bar at the bottom of the screen. The result of the query is shown in the Database Console at the bottom of the page. Executing the query shown at the beginning of this blog results in this output.

Executed query window