gpt4 book ai didi

php - mysqli 查询,里面有 mysql 函数

转载 作者:行者123 更新时间:2023-11-29 20:42:00 26 4
gpt4 key购买 nike

我正在尝试使用我在某个地方找到的函数在数据库上生成密码。如果我直接在数据库上使用 sql 查询,它会根据需要生成一个字符串,但在我的 php 页面中它会给出错误:

"Fatal error: Uncaught Error: Call to a member function fetch_array() on boolean"

$query_rsCaptchaID = "DELIMITER $$
DROP FUNCTION IF EXISTS `randomPasswordGenerator` $$
CREATE FUNCTION `randomPasswordGenerator`(
) RETURNS varchar(64) CHARSET utf8
BEGIN
DECLARE charCount TINYINT(1) DEFAULT 0;
DECLARE charDiceRoll TINYINT(2);
DECLARE randomChar CHAR(1);
DECLARE randomPassword CHAR(64) DEFAULT '';
REPEAT
SET charCount = charCount + 1;
SET charDiceRoll = 1 + FLOOR(RAND() * 94);
IF (charDiceRoll <= 32)
THEN
SET randomChar = ELT(charDiceRoll,
'`', '~', '!', '@', '#', '$', '%', '^',
'&', '*', '(', ')', '-', '=', '_', '+',
'[', ']', '{', '}', '\\', '/', '|', '?',
';', ':', '\'', '\"', ',', '.', '<', '>');
ELSEIF (charDiceRoll >= 33)
AND (charDiceRoll <= 68)
THEN
SET charDiceRoll = charDiceRoll - 33;
SET randomChar = CONV(
charDiceRoll,
10, 36);
ELSE
SET charDiceRoll = charDiceRoll - 59;
SET randomChar = LOWER(
CONV(
charDiceRoll,
10, 36)
);
END IF;
SET randomPassword = CONCAT(randomPassword, randomChar);
UNTIL (charCount = 64)
END REPEAT;
RETURN randomPassword;
END $$
DELIMITER ;
SELECT randomPasswordGenerator() AS captchaID;";
$rsCaptchaID = mysqli_query($db,$query_rsCaptchaID);
$row_rsCaptchaID = $rsCaptchaID->fetch_array();

有人有什么想法吗?我对 MySQLi 很陌生,不会说英语,抱歉有错误。

最佳答案

发生该错误是因为您的查询失败。在您发布的最后两行之间,您需要进行一些错误检查:

$rsCaptchaID = mysqli_query($db,$query_rsCaptchaID);
if(!$rsCaptchaID) die(mysqli_error($db); // <- will show you the SQL error
$row_rsCaptchaID = $rsCaptchaID->fetch_array();

关于php - mysqli 查询,里面有 mysql 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38590831/

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