PhpStorm 2019.3 Help

Run a query

To run a query, create a new or open an existing SQL file, connect it to a data source, and run your code. In the Services tool window, you can view data sources (1), connection sessions (2), and attached files (3). The small green light indicates that you are connected to a data source.

The Services tool window

Run statements from an opened file

In PhpStorm, you can open and run an SQL file. Limitation for the SQL file size is 20 MB. When you open a file that is larger than 20 MB, you see only first 2.5 MB of the file.

  1. Open the Project tool window (View | Tool Windows | Project) and double-click an SQL file.

  2. Click the statement that you want to execute. To run a selection of several statements, select (highlight) the statements.

  3. Press Ctrl+Enter or select Execute from the context menu.

  4. (Optional) If the SQL file is not connected to a data source, select or create a connection session in the Sessions window. For more information about sessions, see Managing connection sessions.

  5. In the Statements window, press Enter to run the selected statement. You can switch between other entries to run another set of statements. Statements that you are going to execute are highlighted in the editor.

Run existing SQL files

Run an SQL file from a hard drive

  1. In the Database tool window (View | Tool Windows | Database), right-click a data source.

  2. Select Run SQL Script.

  3. In the Select Path window, navigate to the SQL file that you want to apply.

Run an SQL file

Run an SQL file for several data sources

  1. In the Project tool window (View | Tool Windows | Project), select the SQL file that you want to run.

  2. Right-click the SQL file, select Run <file_name> (or press Ctrl+Shift+F10).

  3. In the Execution target window, select the necessary data sources or schemes.

Run an SQL file for several data sources

Execute statements in a database console

When you create a data source, a database console is created automatically. For more information about database consoles, see Database consoles.

  1. In the Database tool window (View | Tool Windows | Database), click the data source.

  2. Open F4 or create (Ctrl+Shift+F10 | New Console) a database console. For more information about working with consoles, see Working with consoles.

  3. Type or paste the statement that you want to execute.

  4. Press Ctrl+Enter. Alternatively, click the Execute icon The Execute icon on the toolbar.

    If you have several statements, select whether you want to execute all statements or a single statement. The suggestion list always contains an item for running all the statements.

Managing connection sessions

Action

Description

Create a connection session to a data source

Click the <session> list and select New session.

Create a connection session to a data source

Attach to an existing connection session

Click the <session> list and select an existing session.

Attach to an existing connection session

Detach a connection session

Click the <session_name> list and select an existing session.

Detach a connection session

Rename a connection session

In the Services tool window, right-click a session and select Rename Session.

Rename a connection session

Move a session or a data source to a separate tab

In the Services tool window, right-click a session or a data source and select Show in New Tab. To revert this action, close the separated tab.

Move a session or a data source to a separate tab

Close all connection sessions

In the Services tool window, right-click a data source and select Close All Sessions.

Close all connection sessions

Productivity tips

Execute a file from the search dialog

  1. Press Shift twice.

  2. In the Search Everywhere dialog, type the filename.

  3. Select a file by using Up and Down arrows.

  4. Press Ctrl+Shift+F10.

  5. Select data sources for which you want to run the file and click OK.

Create a database console

To create a console, use one of the following actions in the Database tool window (View | Tool Windows | Database).

  • Click a data source and select File | New | Console.

  • Right-click a data source and select New | Console.

  • Click a data source, press Alt+Insert, and select Console.

  • Click a data source, press Ctrl+Shift+F10, and select New console.

Open a console

  • In the Project tool window (View | Tool Windows | Project), navigate to Scratches and Consoles | Database Consoles | <data_source_name>, double-click a console file.

  • In the Database tool window, click the Jump to console icon (the Jump to console icon ) and select a console.

  • Click a data source, press F4, and select the console that you need.

Open a console

Save a console as a file

In the console file, press Ctrl+Shift+S. Navigate to the directory where you want to store the file.

Save the console contents as a file
Last modified: 9 December 2019