How can I escape the # in PHP? When I use it in a query it turns the remaining line of code into a comment. This is what I have right now:
$columns = "head1, #_search, #_stuff";
$result = mysql_query("SELECT $columns from table LIMIT $k,$j");
I can't just put escape # right after $columns
since it will just become a comment.
~edit: yes I probably should have copied the code directly, but some of it is confidential and much more complicated.
You should be using quotes
for your strings:
$columns = 'head1, #_search, #_stuff';
However, this still doesn't make much sense.
It's also recommended to favour PDO
or mysqli
over mysql_*
尝试添加反斜杠
$columns = 'head1, \#_search, \#_stuff';
它不是字符串文字吗?
$columns = 'head1, #_search, #_stuff'
How about the following ? :
$columns = "head1, `#_search`, `#_stuff`";
You can use `(backtick) to quote reserved words.
If you want to quote table/column name you can do the following example:
SELECT * FROM `#table1` WHERE `#table1`.`#column1` = 1;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.