Is there any alternative checking technique for valid mysql function/keyword in PHP?
views:
37answers:
2The list of reserved words changes between different MySQL versions, and whether built-in function names can also be used as raw schema names varies depending on the sql_mode (in particular IGNORE_SPACE
, which is set in ANSI
mode).
So, if what you're trying to do is test a potential schema name for validity, no: you can't tell whether a schema name is going to be clear or not, short of actually connecting to the database and trying to execute some SQL using the keyword in question. Better to quote schema names to avoid the issue. (A pity, then, that MySQL's schema-name quotes are backticks instead of the ANSI-standard double-quotes. Again, this is something ANSI sql_mode can fix.)
The list of builtin functions in mysql is not available programmatically. See this bug.
Same deal for keywords, however there is a pretty nice list of keywords in the mysql manual with info about the version in which each keyword was introduced.