PhpStorm 2016.3 Help

Managing Data Sources

On this page:

Data sources

To be able to work with your databases in PhpStorm, you should define them as data sources.

In addition to data sources that correspond to real databases (DB data sources), PhpStorm also supports DDL data sources. These are represented by one or more SQL files containing data definition language statements (SQL DDL statements).

Metaphorically, DDL data sources function as databases without data.

Data sources provide the basis for SQL coding assistance and code validation.

Defining a database as a data source

  1. Open the Database tool window and click /help/img/idea/2016.3/iconManageDataSources.png on the toolbar.
  2. In the Data Sources and Drivers dialog that opens, click /help/img/idea/2016.3/new.png and select the database management system (DBMS) that you are using.
  3. In the Name field, if necessary, edit the name of the data source.
  4. If there is the message Download missing driver files in the lower part of the dialog, specify the driver files.

    (To interact with a database, PhpStorm needs a database driver. The drivers, generally, are DBMS-specific.)

    Do one of the following:

    • To download the necessary driver, click the Download link.
    • To specify the driver files that you already have available on your computer, click the <DriverName> link to the right of Driver.

      On the page where the driver settings are shown, under JDBC drivers / Additional, click /help/img/idea/2016.3/new.png and select the files in the dialog that opens.

      Go back to the page with the data source settings.

  5. Specify the database settings.

    For most of the DB management systems, these are the database host name (or IP address), port, the database name, and also your database user name and password.

    If your database is a local file or directory (which may be the case for SQLite, H2, Derby or HSQLDB), you should specify the location of that file or directory. To do that, click /help/img/idea/2016.3/browseButton.png to the right of the File or Path field and select the database file or directory in the dialog that opens.

  6. To access your database using SSH or SSL, select the SSH/SSL tab and specify the corresponding settings there.
  7. To make sure that the settings are correct and PhpStorm can properly interact with your database, click Test Connection on the General tab.
  8. Click OK to save the settings and close the dialog.

    As a result, your new data source is shown in the Database tool window, and the input pane of the associated database console opens.

Creating a DB data source for H2 or SQLite by means of drag and drop

If you have H2 or SQLite database files available locally, you can create DB data sources for them by dragging the files to the Database tool window. The files can be dragged from the Project tool window, or from your file manager (e.g. Explorer or Finder).

  1. If the database files are in your project folder, open the Project tool window. Otherwise, open your file manager.
  2. Open the Database tool window.
  3. Select the file or files of interest in the Project tool window, or in your file manager.
  4. Drag the selected file or files into the Database tool window. (For each of the files a separate data source will be created.)
    /help/img/idea/2016.3/DBNewDBDragAndDrop.png
  5. If you don't have the necessary database driver files yet, you can download them now. Click /help/img/idea/2016.3/iconManageDataSources.png on the toolbar of the Database tool window. (Alternatively, select Properties from the context menu.)
  6. In the Data Sources and Drivers dialog that opens, within the line Download missing driver files, click the Download link.
  7. Click Test Connection to make sure that PhpStorm can properly communicate with the database.
  8. Click OK in the Data Sources and Drivers dialog.

Creating DB data sources by importing connection settings

Files that contain database connection settings (configuration.php) can be used for creating DB data sources.

  1. If the files that you want to import the settings from are not in your project yet, copy them there.
  2. Open the Database tool window.
  3. Do one of the following:
    • Click /help/img/idea/2016.3/new.png on the toolbar and select Import from sources.
    • Right-click the area under the toolbar or any of the existing data sources, point to New and click Import from sources.

    The Data Sources and Drivers dialog opens. The names of candidate data sources are shown in the left-hand pane in green.

  4. Specify the driver files if they are missing.

    Do one of the following:

    • To download the necessary driver, click the Download link.
    • To specify the driver files that you already have available on your computer, click the <DriverName> link to the right of Driver.

      On the page where the driver settings are shown, under JDBC drivers / Additional, click /help/img/idea/2016.3/new.png and select the files in the dialog that opens.

      Go back to the page with the data source settings.

  5. Click Test Connection to make sure that PhpStorm can properly communicate with the database.
  6. Click OK in the Data Sources and Drivers dialog.

Creating a DDL data source

  1. Open the Database tool window and click /help/img/idea/2016.3/iconManageDataSources.png on the toolbar.
  2. In the Data Sources and Drivers dialog that opens, click /help/img/idea/2016.3/new.png and select DDL Data Source.
  3. In the Name field, if necessary, edit the name of the data source.
  4. Under DDL Files, click /help/img/idea/2016.3/new.png and select the necessary SQL file or files in the dialog that opens.
  5. From the Extend list, if necessary, select another data source as a parent. As a result, the data source whose properties you are editing will "inherit" all the DDL definitions from its parent.
  6. Click OK to save the settings and close the dialog.

Creating a DDL data source by means of drag and drop

You can create DDL data sources by dragging DDL SQL files to the Database tool window. The files can be dragged from the Project tool window, or from your file manager (e.g. Explorer or Finder).

  1. If the necessary DDL SQL files are in your project folder, open the Project tool window. Otherwise, open your file manager.
  2. Open the Database tool window.
  3. If you already have one or more DDL data sources defined but there are no DB data sources, expand one of the data source nodes in the Database tool window.
  4. Select the file or files of interest in the Project tool window, or in your file manager.
  5. Drag the selected file or files into the Database tool window. For a new data source to be created, the red border, when dropping the file or files, should surround most of the window area (rather than one of the existing data sources).
    /help/img/idea/2016.3/DBNewDDLByDragAndDrop.png

Changing data source settings

  1. Open the Database tool window and select the data source of interest.
  2. Do one of the following:
    • Click /help/img/idea/2016.3/iconManageDataSources.png on the toolbar.
    • Select Properties from the context menu.
    • Press Alt+Enter .
  3. In the Data Sources and Drivers dialog that opens, edit the settings as necessary. See:

Removing data sources

To remove unnecessary data sources, you can use the Database tool window or the Data Sources and Drivers dialog.

Using the Database tool window. Select the data sources to be removed and do one of the following:

  • Press Delete.
  • Select Delete from the context menu.
  • Select Edit | Delete.

Using the Data Sources and Drivers dialog. Select the data sources to be removed and do one of the following:

  • Click /help/img/idea/2016.3/delete.png on the toolbar.
  • Press Delete.
  • Select Remove from the context menu.
Last modified: 23 March 2017