PhpStorm 2025.1 Help

Quick start with database functionality

This quick start guide will introduce you to the key concepts and help you with your first steps in working with databases in PhpStorm.

Before you start

Enable the Database Tools and SQL plugin

This functionality relies on the Database Tools and SQL plugin, which is bundled and enabled in PhpStorm by default. If the relevant features are not available, make sure that you did not disable the plugin.

  1. Press Ctrl+Alt+S to open settings and then select Plugins.

  2. Open the Installed tab, find the Database Tools and SQL plugin, and select the checkbox next to the plugin name.

Step 1. Create a data source

Depending on a database vendor (MySQL, PostgreSQL, Oracle, and so on), you need to create a corresponding data source to use it to connect to the database.

Data source

Data source is a connection configuration. It stores a list of connection details that are used to establish connection to a database. For example, host, port, database name, driver, SSH and SSL configuration settings, and so on. In data source settings, you can also select databases and schemas for introspection and display in Database tool window, and change the driver for your connection.

Find more information about data sources in Data sources.

In this tutorial, you will set up a demo data source and connect to a demo database. To do this, you can either use the PostgreSQL or MySQL sample databases deployed remotely or download and use the SQLite sample database file.

You can also set up this demo data source using the connection credentials of a database you have setup and running somewhere else. To do this and connect to your database, enter the credentials or its JDBC URL in the corresponding fields of Data Source and Drivers dialog that is described in this tutorial.

  1. In PhpStorm, go to Database tool window (View | Tool Windows | Database or ⌘ 1) .

  2. Click the Create data source link.

  3. Navigate to Data Source and select PostgreSQL.

    Select the $postgresql% data source

PhpStorm will open a Data Source and Drivers dialog with the settings of your new data source.

The new data source settings
  1. In PhpStorm, go to Database tool window (View | Tool Windows | Database or ⌘ 1) .

  2. Click the Create data source link.

  3. Navigate to Data Source and select MySQL.

    Select the mysql% data source

PhpStorm will open a Data Source and Drivers dialog with the settings of your new data source.

The new data source settings
  1. Prepare the SQLite sample database file by downloading from a GitHub repository, then copy the downloaded file to clipboard.

  2. In PhpStorm, paste the SQLite database file to the IDE project root directory.

    To do that, in the Project tool window (View | Tool Windows | Project or Alt+1) , click any area and press Ctrl+V. In the Copy dialog that appears, click OK.

    Paste the database file to the Project tool window
  3. Go to Database tool window (View | Tool Windows | Database or ⌘ 1) .

  4. Click the Create data source link.

  5. Navigate to Data Source and select SQLite.

    Select the sqlite% data source

PhpStorm will open a Data Source and Drivers dialog with the settings of your new data source.

The new data source settings

    Then, set up your new data source with the connection settings of your database.

    1. In the Name field of the dialog, enter your new data source's name. For example, Demo DB.

    2. If there is a the Warning icon Download missing driver files link at the bottom of the connection settings area, click it to download the JDBC driver.

      The new data source settings
    3. In the Host field, enter the following server address:

      postgresql.datagrip-dbs.intellij.net
    4. Make sure that the Port field contains the PostgreSQL default value: 5432.

    5. In the User field, enter the demo user name: datagrip.

    6. In the Password field, enter the password: datagrip.

    7. In the Database field, enter the database name: datagrip.

    8. To make sure that the connection can be successfully established, click the Test Connection link at the bottom of the connection details area.

      Successful connection to the database
    9. In the Schemas tab, make sure that the datagrip database that you will work with is selected.

      Selecting schemas to display in the Data Source and Drivers dialog
    10. Click OK to create the data source.

      Settings of a new data source in the Data Source and Drivers dialog

    Once the data source is created, it appears in the Database tool window.

    New data source in Database Explorer
    1. In the Name field of the dialog, enter your new data source's name. For example, Demo DB.

    2. If there is a the Warning icon Download missing driver files link at the bottom of the connection settings area, click it to download the JDBC driver.

      The new data source settings
    3. In the Host field, enter the following server address:

      mysql.datagrip-dbs.intellij.net
    4. Make sure that the Port field contains the MySQL default value: 3306.

    5. In the User field, enter the demo user name: datagrip.

    6. In the Password field, enter the password: datagrip.

    7. In the Database field, enter the database name: datagrip.

    8. To make sure that the connection can be successfully established, click the Test Connection link at the bottom of the connection details area.

      Successful connection to the database
    9. In the Schemas tab, make sure that the datagrip database that you will work with is selected.

      Selecting schemas to display in the Data Source and Drivers dialog
    10. Click OK to create the data source.

      Settings of a new data source in the Data Source and Drivers dialog

    Once the data source is created, it appears in the Database tool window.

    New data source in Database Explorer
    1. In the Name field of the dialog, enter your new data source's name. For example, Demo DB.

    2. If there is a the Warning icon Download missing driver files link at the bottom of the connection settings area, click it to download the JDBC driver.

      The new data source settings
    3. In the File field, enter the path to your database file in the project root: demo_db.sqlite.

      ALternatively, click the OPen icon Open and navigate to the file.

    4. To make sure that the connection can be successfully established, click the Test Connection link at the bottom of the connection details area.

      Successful connection to the database
    5. In the Schemas tab, make sure that the main database that you will work with is selected.

      Selecting schemas to display in the Data Source and Drivers dialog
    6. Click OK to create the data source.

      Settings of a new data source in the Data Source and Drivers dialog

    Once the data source is created, it appears in the Database tool window.

    New data source in Database Explorer

      Step 2. Write and run SQL queries

      With the Database Tools and SQL plugin, you can write SQL and NoSQL code in query consoles that are attached to data sources. When you create a new data source, the IDE creates a default query console for that data source.

      Query console

      Query consoles are SQL files in which you can compose and execute SQL statements. Unlike the usual SQL files, they are attached to your data source by default.

      For more information about query consoles, refer to the Query consoles topic.

      In this tutorial, we will run simple queries in the default query console that PhpStorm creates and opens upon the new data source creation.

      1. In the default query console, enter the following SQL query:

        SELECT * FROM actor;
      2. To run the query, click the Execute icon Execute on the editor toolbar.

        PhpStorm will run the query and display query result set in the data editor tab of Services tool window (View | Tool Windows | Services or Alt+8) for you to analyze.

      At this step, no schema is selected as the current one in the <schema> dropdown on the console toolbar. However, the query can still be executed because PhpStorm will use the default schema of the data source.

      For more information about how to set a default schema, refer to the Schemas topic.

      1. In the default query console, enter the following SQL query:

        SELECT * FROM actor;
      2. To run the query, click the Execute icon Execute on the editor toolbar.

        PhpStorm will run the query and display query result set in the data editor tab of Services tool window (View | Tool Windows | Services or Alt+8) for you to analyze.

      At this step, no schema is selected as the current one in the <schema> dropdown on the console toolbar. However, the query can still be executed because PhpStorm will use the default schema of the data source.

      For more information about how to set a default schema, refer to the Schemas topic.

      1. In the default query console, enter the following SQL query:

        SELECT * FROM actor;
      2. To run the query, click the Execute icon Execute on the editor toolbar.

        PhpStorm will run the query and display query result set in the data editor tab of Services tool window (View | Tool Windows | Services or Alt+8) for you to analyze.

      At this step, no schema is selected as the current one in the <schema> dropdown on the console toolbar. However, the query can still be executed because PhpStorm will use the default schema of the data source.

      For more information about how to set a default schema, refer to the Schemas topic.

        Step 3. Explore the database

        Now you can explore your database and database objects in a tree view and also open the objects to view their data. With the Database Tools and SQL plugin, you can do this in Database tool window.

        Database Explorer

        Database tool window is a tool window that displays the database structure as a tree with nodes. You can create folders and move data sources to them, assign colors to data sources, filter the database objects, and so on.

        For more information about the tool window, refer to the Database tool window topic. For more information about the tree icons, refer to the Data sources and their elements chapter.

        For example, let us navigate to the actor table and its columns.

        1. In the Database tool window, double-click the Demo_DB data source name to expand the list of introspected databases.

        2. Then, double-click the nodes or click the the Expand icon arrow icon near them to expand the list of items: datagrip | public | tables | actor | columns.

        3. To view the actor table data, double-click its name.

        PhpStorm will open the actor table in a data editor tab.

        1. In the Database tool window, double-click the Demo_DB data source name to expand the list of introspected schemas.

        2. Then, double-click the nodes or click the the Expand icon arrow icon near them to expand the list of items: datagrip | tables | actor | columns.

        3. To view the actor table data, double-click its name.

        PhpStorm will open the actor table in a data editor tab.

        1. In the Database tool window, double-click the Demo_DB data source name to expand the list of introspected . schemas

        2. Then, double-click the nodes or click the the Expand icon arrow icon near them to expand the list of items: main | tables | actor | columns.

        3. To view the actor table data, double-click its name.

        PhpStorm will open the actor table in a data editor tab.

          Step 4. View, sort, and filter the data

          With the Database Tools and SQL plugin, you can view and edit the data of database tables and views in the data editor and viewer.

          Data editor and viewer

          The data editor and viewer, or data editor, provides a user interface for working with data. In the data editor, you can sort, filter, add, edit, and remove the data as well as perform other associated tasks.

          For more information about data editor, refer to the Data editor and viewer topic.

          In this tutorial, we will sort the first_name column of actor table alphabetically and will also filter the last_name column to see the last names that start with JO.

          1. To sort the data, in the data editor tab, click the arrows icon in the first_name column header. PhpStorm will send the ORDER BY query to the database and display its result in the editor.

            For more information about sorting data on the database side and on the client side, refer to the Sort data topic.

          2. To filter the data, in the data editor tab, click the Filter icon Local Filter in the last_name column header. Enter JO in the search field and select the Value checkbox, then click any area in the data editor.

            PhpStorm will filter the data and display the result.

          For more information about filtering data in the IDE, refer to the Filter data topic.

          1. To sort the data, in the data editor tab, click the arrows icon in the first_name column header. PhpStorm will send the ORDER BY query to the database and display its result in the editor.

            For more information about sorting data on the database side and on the client side, refer to the Sort data topic.

          2. To filter the data, in the data editor tab, click the Filter icon Local Filter in the last_name column header. Enter JO in the search field and select the Value checkbox, then click any area in the data editor.

            PhpStorm will filter the data and display the result.

          For more information about filtering data in the IDE, refer to the Filter data topic.

          1. To sort the data, in the data editor tab, click the arrows icon in the first_name column header. PhpStorm will send the ORDER BY query to the database and display its result in the editor.

            For more information about sorting data on the database side and on the client side, refer to the Sort data topic.

          2. To filter the data, in the data editor tab, click the Filter icon Local Filter in the last_name column header. Enter JO in the search field and select the Value checkbox, then click any area in the data editor.

            PhpStorm will filter the data and display the result.

          For more information about filtering data in the IDE, refer to the Filter data topic.

            Next steps

            After going through this tutorial, you can create a connection configuration and connect to a database using its JDBC URL, explore the connected database, run SQL queries in query consoles, and view the query results. Also, you can view, sort, and filter database object data.

            To learn more about the IDE, consider the following topics and sections:

            Create a data source

            Use the instructions for various database vendors to create data sources for your databases.

            Data editor and viewer

            Learn about the features you can use for viewing and managing data of database objects, query result sets, and DSV files.

            Query consoles

            This topic gives an idea of what the query console is and how to work with it in the IDE.

            Query results

            This topic describes the ways of viewing query results.

            Write and edit source code

            Find descriptions of the code editor features that you can use in query consoles, SQL files, and scratch files.

            Export

            Learn how to export data and database objects.

            Database diagrams

            Learn how to view diagrams of your databases and schemas.

            Last modified: 04 February 2025