如何在Google Cloud SQL中防止SQL注入?
我正在使用Python与谷歌的新Cloud SQL(mySQL)数据库进行交流。我有一个可以正常工作的例子,但我想知道这个示例代码是否足够防止SQL注入攻击。
mdata = self.request.get('mdata')
conn = rdbms.connect(instance=_INSTANCE_NAME, database='metarsql')
cursor = conn.cursor()
# Note that the only format string supported is %s
cursor.execute('INSERT INTO metar (metar_data) VALUES (%s)', (MySQLdb.escape_string(mdata)))
conn.commit()
conn.close()
有没有什么函数或者命令可以用来防止SQL注入?比如说,有没有什么函数可以阻止多个SQL命令的执行?
在谷歌搜索Cloud SQL和注入攻击时,找到的信息不多。
最好的祝愿
安德烈·F·布鲁顿