30
votes

I'm getting unable to resolve table errors appear in php files containing SQL querying valid tables.

enter image description here

If I Ctrl + Enter over the query, then I get expected results in the DB console, and if I expand the database in the DB explorer tab then I can see the tables.

It's not affecting code execution, but it's annoying because it catches my eye when writing code, and it masks real SQL errors.

I've tried refreshing the database connection, and I've verified that the php tab is connecting to the correct database.

12
1) Try re-creating DB connection from scratch (delete that one and create again); 2) Make sure that one of the databases is selected as "default" (basically -- a tick in "resolve unqualified references" column for that DB). Ideally work with db logins that can see only 1 DB; 3) Maybe it conflicts with another DB-oriented plugin (try with ALL non-bundled plugins disabled); 4) And please always state exact IDE version used - LazyOne
@LazyOne - Deleting and recreating the datasource worked, thanks. I'll mark it accepted if you copy the comment to an answer. - Parris Varney

12 Answers

43
votes

In 2017.2 I had to go to

Settings > Languages & Frameworks > SQL Resolution Scopes

and add my project and database link in there to get it right again.

17
votes

Try re-creating DB connection from scratch (delete existing one and create it again).


Thinking of possible reasons ... I can think of this scenario:

  • working with project in current stable version (currently 2016.1.x);
  • trying EAP build for next version (2016.2 at this moment) on this project and make some DB-related changes there (even simple syncing DB);
  • going back to stable version (2016.1.x) .. and because new version uses newer file format/versioning for DB-related data (cached DB structure etc) IDE may start ignoring "unknown/newer" format for such data and instead of throwing appropriate warning it just "silently" throwing "unresolved table" message.

No other ideas.

12
votes

I was getting what OP was getting, and the problem was my DB Server was MariaDB and i had MySQL selected as the SQL Dialect.

See File > Settings: Languages & Frameworks > SQL Dialects.

11
votes

Faulty error pollution DRIVES ME NUTS TOO!

If I start having SQL resolution issues, I will check my resolution scopes (settings -> Languages & Frameworks -> SQL Resolution Scopes).

Generally I have the most issues when my project mapping is set to 'All Data Sources' by default.

The following steps always fixes it for me:

  • Click the Project Mapping Dropdown
  • Uncheck the global 'All Data Sources' setting (required to make other selection available)
  • Click the drop down arrow for your Database connection
  • Check 'All Schemas' (Or Specific Tables)
  • Click OK to close the settings window

Your false resolution errors should disappear after the next parse cycle.

You aren't limited to applying the above steps to just one DB connection, you can do it for all connections in your project.


Sometimes adding a custom resolution scope will work as well, but it is hit or miss for me.

  • Click the plus sign (top right)
  • Select the file you are working on and hit 'OK'
  • Select the 'Resolution Scope' column
  • Deselect 'all data sources'
  • Select the specific DB resources you want

Reconnecting to the DB never works for me.

Specifying the table works well... but it can become very cumbersome as the project grows.


I have also run into an additional situation where PHPStorm would only resolve some of my queries, no matter what scope resolution settings I used. However, after I attached a console to my file, they resolved just fine. (Search for 'Attach Console' in Help | Find Action. You can also add it to a 'Quick List' or Keymap it.)

5
votes

Although this answer is specifically for phpstorm, I had this same issue in IntelliJ and none of the above fixes worked for me. I had my scope added, everything was active. I could query the database in the console window perfectly fine, and I was totally stumped.

Eventually, I noticed some text in the database panel that said 0 of 4 in tiny text. It looked like this:

Database panel showing the 0 of 4 message

Upon clicking on the 0 of 4 text, I discovered there were no schemas added to the connection, even though a default database was set upon making the connection originally. Going to that page allows you to add schemas. Be sure to either select "All schemas", "Current schema", or the specific database that you want to use with your connection.

5
votes

Changed dialect to MariaDB on global and project level.

enter image description here

OR

enter image description here

4
votes

To dismiss this error in PHPStorm versions before 2017 which have no SQL Resolution Scopes option:

  1. Go to File
  2. Go to Settings...
  3. Go to Editor and then Inspections
  4. In SQL chapter uncheck Unresolved reference
  5. Click Apply and then OK
4
votes

Adding database name before the table name worked in my case.

For instance, instead of writing SELECT * FROM Client, put SELECT * FROM database.Client.

2
votes

I will add another answer, because for me, it was a completely different (embarrassing) cause:

I somehow forgot to add the database name in the data sources general settings (where you also set the host, user and password).

1
votes

In my case, I have clicked the right button in the SQLScript and change the Dialect to "Generic SQL". It worked for me.

0
votes

I solved this problem as follows:

  1. CTRL + SHIFT + F10
  2. new query console
  3. Write a selection query to the database, for example:
SELECT * FROM user WHERE user_email='$email' AND user_password='$password'
  1. Enter your code page and click on the table name in the query
  2. ALT + ENTER
  3. run query in console
  4. Select the console you created
0
votes

First, you need to check the Schemas tab, and make sure you've added the database.

If the unable to resolve table error stills appears, there're two options to fix this:

1.You can edit the properties of the Data Source and add the name of Database, then you can see that select * from table works well.

2.On the other hand, you can also use sql like this select * from database.table. It works for me.

By the way, in many situations, autocomplete can be very useful.