gpt4 book ai didi

php - CodeIgniter 中的 MySQL 安全性

转载 作者:行者123 更新时间:2023-11-29 01:32:21 25 4
gpt4 key购买 nike

我是 CodeIgniter 的新手,但不是 PHP 的新手,我想知道我需要在 CodeIgniter 中做什么才能使我的所有查询安全。

通常,我只是对查询中使用的每个变量使用 mysql_real_escape_string()(标准 PHP),但我看了一个关于 CodeIgniter 的教程,作者没有转义变量,只是做了如下所示的标准插入:

$this->db->query("SELECT * FROM Users WHERE Username = ?", array($username));

哪种方式是正确的?

最佳答案

您的示例执行 parameter binding

正如您在上述链接的最后一段中所读到的,绑定(bind)会自动转义传递给查询的值:

The secondary benefit of using binds is that the values are automatically escaped, producing safer queries. You don't have to remember to manually escape data; the engine does it automatically for you.

关于php - CodeIgniter 中的 MySQL 安全性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8203149/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com