Importance of backtick around table name in MySQL query

后端 未结 3 2081
野的像风
野的像风 2020-12-15 22:43

In MySQL queries, how important is it to put backticks around a table name. Does it have something to do with security? Are MySQL injection attacks possible through the ta

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-15 23:09

    In MySQL queries, how important is it to put backticks around a table name. Does it have something to do with security?

    As far as backticks are concerned, I use them when there is name conflict between mysql-specifcs names and those from query.

    Are MySQL injection attacks possible through the table name if the table name is created dynamically in PHP based on user inputs?

    When ever there is a user input, you need to make sure that you filter and validate the input coming from the user. So yes there is security risk to it.

    I would recommend you to use intval for numbers and mysql_real_escape_string function for any variables that you may use in your queries.

提交回复
热议问题