Ben Rhys-Lewis Ben Rhys-Lewis - 5 months ago 60x
SQL Question

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


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.