PHP 中的 mysqli 类是否可以 100% 保护 sql 注入?

Does mysqli class in PHP protect 100% against sql injections?(PHP 中的 mysqli 类是否可以 100% 保护 sql 注入?)
本文介绍了PHP 中的 mysqli 类是否可以 100% 保护 sql 注入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我看过很多关于 mysqli 的文章和问题,他们都声称它可以防止 sql 注入.但它是万无一失的,还是有办法绕过它.我对跨站脚本或网络钓鱼攻击不感兴趣,只对 sql 注入感兴趣.

I've seen lots of articles and questions about mysqli, and all of them claim that it protects against sql injections. But is it fool proof, or is there still some way to get around it. I'm not interested in cross site scripting or phishing attacks, only sql injections.

我应该首先说的是我使用的是准备好的语句.这就是我对 mysqli 的意思.如果我使用没有任何字符串连接的准备好的语句,那么它是万无一失的吗?

What I should have said to begin with is that I am using prepared statements. That is what I meant with mysqli. If I use prepared statements without any string concatenation, then is it foolproof?

推荐答案

但它是万无一失的,还是有办法绕过它.

But is it fool proof, or is there still some way to get around it.

不,你必须知道你在做什么.如果您使用绑定参数(MySqli 附带的一项功能),您就可以完全避免注入类型的攻击来自这个攻击向量.这不会阻止您 - 程序员 - 直接嵌入字符串,从而启用注入攻击.您必须按预期使用该功能.

No, you have to know what you're doing. If you use bound parameters (A feature that MySqli comes with), you are completely safe from injection type attacks from this attack vector. This doesn't prevent you - the programmer - from embedding strings directly, and thereby enabling injection attacks. You have to use the feature as intended.

我应该首先说的是我使用的是准备好的语句.这就是我对 mysqli 的意思.如果我使用没有任何字符串连接的准备好的语句,那么它是万无一失的吗?

What I should have said to begin with is that I am using prepared statements. That is what I meant with mysqli. If I use prepared statements without any string concatenation, then is it foolproof?

万无一失仍然是一个如此危险的词.但是对于通过准备好的语句绑定的变量,您可以避免注入攻击.这是因为绑定参数与 SQL 查询分开传输.与传统"嵌入字符串方法,数据库服务器需要解析输入,其中有很多边缘情况(字符集等).当数据和查询分开发送时,没有实际的解析进行(至少没有解析变量数据).

Foolproof is still such a dangerous word. But you are safe from injection attacks for the variables that are bound through prepared statements. This is because bound parameters are transmitted separately from the SQL query. With the "traditional" embed-string approach, the database server needs to parse the input and there are lots of edge cases in that (Charsets etc.). When the data and the query are sent separate, there is no actual parsing going on (At least not parsing of the variable data).

这篇关于PHP 中的 mysqli 类是否可以 100% 保护 sql 注入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Warning: mysqli_query() expects at least 2 parameters, 1 given. What?(警告:mysqli_query() 需要至少 2 个参数,1 个给定.什么?)
INSERT query produces quot;Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean givenquot;(INSERT 查询产生“警告:mysqli_num_rows() 期望参数 1 为 mysqli_result,给出布尔值;)
prepared statements - are they necessary(准备好的陈述 - 它们是否必要)
Do I need to escape my variables if I use MySQLi prepared statements?(如果我使用 MySQLi 准备好的语句,是否需要转义我的变量?)
Properly Escaping with MySQLI | query over prepared statements(使用 MySQLI 正确转义 |查询准备好的语句)
Is it possible to use mysqli_fetch_object with a prepared statement(是否可以将 mysqli_fetch_object 与准备好的语句一起使用)