Search code examples
phpstormprestashopprestashop-1.6

How to resolve SQL table with prefix in PhpStorm?


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