问题
I am using PHPStorm and having some interesting errors/warnings showing up. Not sure if I skipped configuring something. Here is a query for example,
$query = "INSERT INTO tblperson (";
$query .= " personName, personLname, personNumber, personPhone, personAttr";
$query .= ") VALUES (";
$query .= " '{$personName}', '{$personLname}', {$personNumber}, {$personPhone}, '{$personAttr}'";
$query .= ")";
And I get this warning: " expected, unexpected end of file" on first line of the code. Is there anything I am missing on this insert statement that PHPStorm warns me on?
When I run the code I can insert a record without any problems but still wonder maybe there might be an improvement that I am missing.
回答1:
After adding the question, I continued searching and hit a similar problem on Stackoverflow which was suggesting SQL Dialects.
PHPStorm has a setting under Preferences, I have changed it from MySQL to <SQL Keywords>
and now it does not warn me on this error anymore.
Just make sure you have selected the project and change the dialect so that all files beneath will inherit the same dialects.
Edit: As stated in the comments, I changed using PDO. The solution above was just avoiding the issue.
回答2:
Adding this here because the other answer only disables the inspection everywhere and not just for a particular statement.
This issue occurs because the editor loses context when the SQL statement is split over multiple strings.
There is no proper way to actually ignore this error for just a single statement in the editor.
This issue can be reproduced by having your SQL inspections turned on and having a dialect set for the file project.
One potential workaround is to have the beginning of your statement split.
For example, change the below statement from
$start = "INSERT IGNORE INTO table1(";
$mid = ") VALUES (";
$end = ")";
to
$start = "INSERT " . "IGNORE INTO table1(";
$mid = ") VALUES (";
$end = ")";
This'll trick PhpStorm into thinking that your statement is just another string instead of treating it as SQL and performing an inspection on it.
I realise there may be other ways to write statements; however this answer allows for the style of statement in the original question while solving the problem of PhpStorm flagging an error for the particular statement.
来源:https://stackoverflow.com/questions/20729064/reference-expected-unexpected-end-of-file-on-phpstorm