简体   繁体   English

在进行INSERT之前,在JSON编码之前,还是在JSON编码之后,你是MySQL真正的转义数据吗?

[英]Prior to doing an INSERT, do you MySQL real escape data before JSON encoding it, or after JSON encoding?

在MySQL中插入JSON编码数据之前,您首先对数据进行JSON编码,然后在插入之前将其转义,或者在JSON编码之前首先转义数据然后插入数据吗?

首先对JSON进行编码,然后在插入数据库之前对其进行转义。

Don't use mysql_real_escape_string - it's deprecated. 不要使用mysql_real_escape_string - 它已被弃用。 http://php.net/manual/en/function.mysql-real-escape-string.php If you use one of the DB libraries such as PDO, then that will do the work for you. http://php.net/manual/en/function.mysql-real-escape-string.php如果您使用其中一个数据库库(如PDO),那么这将为您完成工作。 See real escape string and PDO 查看真正的转义字符串和PDO

The very statement of question is wrong. 问题的陈述是错误的。

  1. Do not store JSON in database. 不要将JSON存储在数据库中。
  2. real escape doesn't make your data safe, as it's implied in your question. 真正的逃避不会使您的数据安全,因为它隐含在您的问题中。
  3. mysql-real-escape-string belongs to mysql - so, the answer is quite obvious. mysql-real-escape-string属于mysql - 所以答案很明显。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM