PhpStorm does not enable you to create databases, but provides facilities to manage and query them. Once you are granted access to a certain database, you can configure one or more data sources within PhpStorm that reflect the structure of the database and store the database access credentials. Based on this information, PhpStorm establishes connection to the database and provides the ability to retrieve or change information contained therein.
In this section:
- Data source scopes
- Data source types
- Database connections
- Overview of the features
Data source scopes
There are the data sources that are available in all of your projects. Such data sources are said to have the IDE scope. Others, ones with the project scope, are available in only one of your projects.
Data source types
PhpStorm supports data sources of the following types:
- DB data sources (also called database connections), which correspond to real databases.
- DDL data sources, which represent the necessary data structures and act as stub databases, the databases without any data. For this data source type you should have one or more SQL DDL files representing the required data structures available in your project directory (or one of its subdirectories). Also note that a particular SQL dialect should be set for all those files (or the directories containing those files).
DB data sources can have the IDE or the project scope; DDL data sources exist only at the project level.
Similarly, all database connections are automatically terminated when you exit the IDE.
The database connection status is shown in the Database tool window at the level of the data source nodes. The data sources with open connections have the text [connected] to the right of their names.
If necessary, you can close all unnecessary database connections manually. To do that:
- In the Database tool window, select the corresponding data source or data sources. (To select more than one data source, use mouse clicks in combination with the Ctrl key.)
Do one of the following:
- Click on the toolbar.
- Select Disconnect from the context menu.
Overview of the features
Here is a very brief overview of PhpStorm features related to working with data sources:
- Support for SQL, which includes syntax and error highlighting, code completion, selection of words and statements, parameter lookup, and refactoring (Introduce constant, for instance).
- The ability to use source files with injected SQL code, with different SQL dialects, configurable at the project, directory, or file level.
- Dedicated Database tool window, where you can configure data sources.
- Database console.