开发者

PHP, MySQL database.`table`, quotes present, I don't understand

I'm working on an app that uses the mysql tables defined in an array. This is so they can be changed quickly for use in the dev/live environments.

Other than issues regarding why the dev environment uses completely different table structure, I've got what I'm hoping is a simple question.

I've got one table defined differently than the others, like so:

'customer' => Array(
  'variables' => 'customer.`variables`'
)

While all the other tables are defined this way:

'customer' => Array(
  'orders' => 'customer.orders'
)

The difference being the pair of ` surrounding the table name. Obviously this isn't a valid table (and I can't find a table named simply 'variables' in the database. Quick ideas how I can track this one down? I'm assuming at this point that it has a special meaning to the MySQL server, however that's just a guess.

Note: There are many o开发者_运维技巧ther tables defined in the same array, I've simply excluded them. Every other definition is like the second example.


An identifier may be quoted or unquoted. If an identifier contains special characters or is a reserved word, you must quote it whenever you refer to it. The set of alphanumeric characters from the current character set, “_”, and “$” are not special. Reserved words are listed at Section 8.3, “Reserved Words”. (Exception: A reserved word that follows a period in a qualified name must be an identifier, so it need not be quoted.)

The identifier quote character is the backtick (“`”):

From http://dev.mysql.com/doc/refman/5.1/en/identifiers.html

Update: In this context, it doesn't seem that variables actually needs escaping. However, automated tools (including MySQL itself) tend to escape it; probably, because the escaping algorithm is not context-sensitive and it merely finds words in a list:

mysql> set sql_quote_show_create=off;
Query OK, 0 rows affected (0.00 sec)
mysql> show create table my_test;
[...]
CREATE TABLE my_test (
  id int(11) DEFAULT NULL,
  `variables` varchar(50) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜