Question

How to disable highlighting for SQL code in phpstorm ? i ever disabled all sql inspection..but color and fonts rules continue to overight my php string color rules . Here is an Exemple for what i want to achieve :

$var_php = " all text here is red , SELECT * and whatever sql code is in red too " ;
Was it helpful?

Solution

SQL Language is automatically injected in strings that contain SQL code (which are detected by the typical patterns, e.g. select xx from etc). It also injected in HEREDOC/NOWDOC if you use special label (SQL).

You can disable these (selected on the screenshot below) and any other unwanted injection rules or create your own at Settings/Preferences | Editor | Language Injections.

enter image description here

P.S. Since you do not need any SQL/DB support at all, you may just disable SQL/database support plugins completely.


If you do like such injections in general but just do not want them in a specific place only (e.g. because of the false positive match) then you can force plain text in that string. For example:

$str = /** @lang Text */ 'Select all entries from my cool database';

enter image description here

Please note that such comment must be placed just before the actual string (so it can be used in function call params or alike), not before the whole variable assignment/statement like ordinary PHPDoc comments.

P.S. The same is possible other way around: force SQL in some string that is not autodetected by Language Injection rules (e.g. when string is split into concatenated bits or uses unknown/unexpected sequence/syntax).

OTHER TIPS

You can disable it while leaving other SQL highlighting / inspections alone by creating a new IntelliLang injection which specifically does not match DQL. I used the presence of the : character. This will prevent the IDE from highlighting DQL, and also marking it as error or reformatting it incorrectly.

I've created a Gist with instructions here:

https://gist.github.com/willemnviljoen/d20ad8ad0cc365a7e80744328246610f

Usually PHPstorm does a pretty good job of deciding when SQL string literals should be inspected as SQL code. For individual cases where it gets it wrong, the most "proper" way to disable inspection for a single line is probably the PHPDoc comment mentioned in another answer, like:

$str = /** @lang Text */ 'Select the answer from the list';

But that seems messy to me. Luckily, you can trick PHPstorm pretty easily, as it seems to ignore the string if the first word in a "sentence" is not a SQL keyword (SELECT/UPDATE etc). So a simple (though a bit more hackish) way is to just split the string, like:

$str = 'Select'.' the answer from the list';
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top