"Unable to resolve column" because the table name is in a variable.

My code structure looks like this:

Even if its not run through the function to get the table name $tbl, the select query always shows "Unable to resolve column".

I know I can turn off inspections completely, what I'm wondering is if there is a way instruct phpstorm as to what the correct table name I'm interested in is.

If I type the actual name into the place of {$tbl} then the connection all works.

I see there is an old issue from 2011 that seems very similar to this topic.  Any way to do this in 2019?

3

Please map the schema for the file at File | Settings | Languages & Frameworks | SQL Resolution Scopes.

0

Each schema is defined by a module in its schema.php file.  They look like this:

 

Is there a way to export the schema from the database to give it to phpstorm in a structure that it understands?

-- edit --

I exported just the schema from the database and added in to
LANGUAGES & FRAMEWORKS -> SQL RESOLUTION SCOPES

Then chose the resolution scope of the project to match the file, but the in the queries in the code still the same error shows.

1
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.

(c) Ben Rhys-Lewis

 

 

Dear JetBrain, can you please add the new feature, to add columns / tables resolving in cases when $table or $field are $variables:

1) to get value from /* @var */ annotation

2) to get value from alias in SQL query, like realColumnName and productsTable and realTableName in following query:

$qry = "SELECT realTableName.$column as realColumnName, $fields
FROM $table realTableName
INNER JOIN $tableProducts productsTable ON (enquiryArticle = o_id)
WHERE realTableName.retailer__id = :retailerId;

 

 

0

请先登录再写评论。