查询名称中带有“&"号的表 [英] Querying table with an ampersand in the name

查看:78
本文介绍了查询名称中带有“&"号的表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在清理MySQL数据库,并且必须在多个表中进行一些类似的更改.这样,我收集了我的表列表

I'm in the process of cleaning up a MySQL database and have to make some similar changes across multiple tables. As such, I gather my list of tables

$query = "
SELECT
    TABLE_NAME
FROM
    information_schema.COLUMNS
WHERE
    TABLE_SCHEMA = 'myDB' AND
    COLUMN_NAME = 'activeColumn'";

然后遍历每个需要更改的地方.问题是这些表中的某些表的标题中有&"号.我猜PHP和/或MySQL对此有问题,因为这引发了我的方向

then iterate through each making the changes I need. The problem is that some of these tables have an ampersand in the title. I guess PHP and/or MySQL has a problem with this, as it throws this my direction

/* $query = "SELECT * FROM Cats&Dogs"; */
You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version for the
right syntax to use near '&Dogs' at line 1

当您需要插入与符号并插入其中时,我已经找到解决此问题的方法数据库,甚至当您在WHERE子句中有一个(说实话,这甚至不是完整的解决方案,但这是我找到的最好的解决方案).如果我在不使用PHP的情况下将确切的查询输入到MySQL中,那么它将起作用.

I've found ways to fix this issue when you need to insert an ampersand in to the DB and even when you have one in the WHERE clause(truthfully, this isn't even a full solution but it's the best I found). If I enter the exact query in to MySQL without using PHP then it works.

什么可能导致此问题?

推荐答案

反引号. SELECT * FROM `Cats&Dogs`.

参考: http://dev.mysql.com/doc/refman/5.0/en/identifiers.html

这篇关于查询名称中带有“&"号的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆