PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, June 30, 2022

[FIXED] How to resolve SQL table with prefix in PhpStorm?

 June 30, 2022     phpstorm, prestashop, prestashop-1.6     No comments   

Issue

I'm working on PhpStorm to develop my Prestashop websites and I can't resolve this issue. I work on localhost and successfully connected PhpStorm to my MySQL Server.

Now PhpStorm throws warnings like "unable to resolve table '${_DB_PREFIX_}cms'". Prestashop uses prefixes for table names and it seems PhpStorm can't resolve those tables with prefixes.

Is there a workaround for this ?

Here is a code exemple from Prestashop-1.6 sources :

$sql = 'SELECT c.`id_cms`, cl.`meta_title`, cl.`link_rewrite`
    FROM `'._DB_PREFIX_.'cms` c
    INNER JOIN `'._DB_PREFIX_.'cms_shop` cs
    ON (c.`id_cms` = cs.`id_cms`)
    INNER JOIN `'._DB_PREFIX_.'cms_lang` cl
    ON (c.`id_cms` = cl.`id_cms`)
    WHERE c.`id_cms_category` = '.(int)$id_cms_category.'
    AND cs.`id_shop` = '.(int)$id_shop.'
    AND cl.`id_lang` = '.(int)$id_lang.
    $where_shop.'
    AND c.`active` = 1
    ORDER BY `position`';

Error in PhpStorm for Mysql tables with prefixes


Solution

Edit: At time of writing (2016) there was no solution to this issue. But since 2018, as mentioned in Christian's answer, you can now use constants in SQL queries.


Actually there is no way to handle that. But you may disable inspection for such warning.

  1. Open File > Settings > Editor > Inspections
  2. Expand SQL
  3. Uncheck Unresolved reference


Answered By - Byscripts
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing