tags:

views:

37

answers:

2

Is there any alternative checking technique for valid mysql function/keyword in PHP?

+1  A: 

The 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.)

bobince
Thanks @boblince. Can we check whether a function is callable or not(regarding sql_mode).
Sadat
What two things are you trying to differentiate? A function keyword and a non-function keyword? I guess you could detect functions by testing to see if the name was accepted as a schema name in normal sql_mode, then switch to `IGNORE_SPACE` mode and test again. If the results are different, it would have to be a function. I don't think there's much useful you could do with this though.
bobince
+1  A: 

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.

Keith Randall