SQL and constants, any way to retain syntax highlighting?

Hi,

On the system I normally use the database tables are held in an array so I get queries like this:
            $sql  = "SELECT *
                      FROM {$jamroom_db['some_table']} ";
            $rows = dbQuery($sql, 'NUMERIC');

but on a new system the table names are defined as constants, so a query looks like this:
            $sql  = "SELECT *
                       FROM ". SOME_TABLE .";
                      WHERE 1 ";
             $rows = dbQuery($sql, 'NUMERIC');

In the first example PhpStorm recognizes that the $sql is a mysql query and highlights the syntax for mysql, but in the second, its all just treated as a normal string.

Is there any way to use constants in an SQL query so that PhpStorm can still highlight the syntax for me?

Thanks

4 comments
Comment actions Permalink

Thanks Andriy,

I wasn't so hopeful, but its good to know for sure.  Much appreciated.

0
Comment actions Permalink

Yea, we just developed a standard to convert constants to a variable like this before SQL use:

$iSQLUserID = _USERID;

$sSQL "SELECT u.first_name FROM users u WHERE u.id=$iSQLUserID";

0
Comment actions Permalink

Nice thinking. :)

0

Please sign in to leave a comment.