Answer
In PhpStorm, a directory‑level SQL dialect override takes precedence over the dialect inferred from a data source mapping when resolving SQL strings inside PHP code.
Only one dialect can be assigned to a given directory (or file). If you need to work with multiple database engines inside the same module, you must use file‑level overrides or inline language‑injection comments rather than trying to assign several dialects to the same directory.
Confirmed facts
- PhpStorm resolves dialects in this order of priority: global setting → directory override → file override → data‑source mapping → language‑injection comment.
- The IDE does not support assigning multiple dialects to a single scope; the last defined override for that scope wins.
Likely explanation
When a PHP file resides in a directory that has a dialect set (e.g., MySQL) but contains SQL strings meant for another data source (e.g., PostgreSQL), the directory override is consulted first. Because it matches the file’s location, the IDE applies that dialect for syntax highlighting and validation, ignoring the data source’s dialect unless a more specific override (file‑level or injection comment) is present.
Steps to verify and configure
- Open
Settings > Languages & Frameworks > SQL Dialects.
- Confirm the directory (or module) you want to override is listed with the intended dialect (e.g.,
src/main/php/mysql → MySQL).
- Check that the data source in the Database tool window is correctly configured for the other engine (e.g., PostgreSQL).
- Open a PHP file containing SQL strings and place the caret inside a string; look at the status bar – it shows the active dialect.
- If the dialect shown matches the directory override, the precedence is confirmed.
- To force a different dialect for specific strings, add a language‑injection comment like
/* language=PostgreSQL */ before the string or set a file‑level override via Right‑click > Override File Dialect.
Missing diagnostic detail
Are the SQL strings you are troubleshooting plain string literals or are they marked with language‑injection comments (e.g., /* language=SQL */)? This determines whether the directory override is applied at all and may change the recommendation.
Verification
After making changes, run a simple query that uses dialect‑specific syntax (e.g., LIMIT 1 for MySQL vs. LIMIT 1 for PostgreSQL) inside an injected string and verify that the IDE does not flag a syntax error when the correct dialect is active.
Global setting, Directory override, File override, Data‑source mapping