Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PhpStorm unable to resolve column for multiple database connections

I have only been using PhpStorm a week or so, so far all my SQL queries have been working fine with no errors after setting up the database connection. This current code actually uses a second database (one is for users the other for the specific product) so I added that connection in the database tab too but its still giving me a 'unable to resolve column' warning.

Is there a way to see what database its looking at? Will it work with multiple databases? Or have I done something else wrong?

Error below:

error message

$this->db->setSQL("SELECT T1.*, trunc(sysdate) - trunc(DATE_CHANGED) EXPIRES FROM " . $this->tableName . " T1 WHERE lower(" . $this->primaryKey . ")=lower(:id)")

Also here is what my database settings window looks like as seen some people having problems with parameter patterns causing this error but I'm fairly sure that is not the issue here:

database settings

Using PhpStorm 10.0.3

like image 413
Ben Rhys-Lewis Avatar asked Apr 22 '16 08:04

Ben Rhys-Lewis


2 Answers

You can use Nowdoc/Heredoc also instead of using

/** @noinspection SqlResolve */

Here is the example

$name = "your name";
$query = <<<SQL
SELECT * FROM user WHERE name LIKE "%$name%" ORDER BY id
SQL;

Both of the methods will make the warning gone

like image 132
HendraWD Avatar answered Sep 28 '22 18:09

HendraWD


So the short answer is that it cant read the table name as a variable even though its set in a variable above. I thought PhpStorm could work that out. The only way to remove the error would be to either completely turn off SQL inspections (obviously not ideal as I use it throughout my project) or to temporarily disable it for this statement only using the doc comment:

/** @noinspection SqlResolve */

Was hoping to find a more focused comment much like the @var or @method ones to help tell Phpstorm what the table should be so it could still inspect the rest of the statement. Something like: /** @var $this->tableName TABLE_IM_USING */ Maybe in the future JetBrains will add that or make PhpStorm clever enough to look at the variable 3 lines above.

like image 42
Ben Rhys-Lewis Avatar answered Sep 28 '22 18:09

Ben Rhys-Lewis