gpt4 book ai didi

PHP MySQLi 为 SELECT 准备的语句(避免 SQL 注入(inject))

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

这是避免此 SELECT 中 SQL 注入(inject)的正确方法吗?

// --[  Method  ]---------------------------------------------------------------
//
// - Purpose : Check if provided $email (taken from user input) exists in the DB
//
// -----------------------------------------------------------------------------
function DB_EmailExists($email)
{
//
if(DB_Connect() == false)
{
echo mysqli_error();
return false;
}

//
$stmt = $GLOBALS['global_db_link']->prepare("SELECT * FROM ".$GLOBALS['global_db_table_users']." WHERE Email=?");
$stmt->bind_param('s', $email);
$stmt->execute();
$stmt->store_result();
$numrows = $stmt->num_rows;
$stmt->close();

//
if ($numrows==0)
{
DB_Disconnect();
return false;
}

//
DB_Disconnect();

return true;
}

最佳答案

是的,这有效。但不需要SELECT *,只需使用SELECT email

关于PHP MySQLi 为 SELECT 准备的语句(避免 SQL 注入(inject)),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33976715/

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