【发布时间】:2016-11-30 03:47:26
【问题描述】:
我正在尝试使用我在某些地方找到的函数在数据库上生成密码。 如果我直接在数据库上使用 sql 查询,它会根据需要生成一个字符串,但在我的 php 页面中它会给出 error:
"致命错误:未捕获错误:调用成员函数 fetch_array() 布尔值"
$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 的新手,不会说英语,如有错误,请见谅。
【问题讨论】:
-
is_a函数已被弃用很长时间(PHP 5.0)。请改用instanceof运算符。 -
我通过 php:
codefunction random_str($length,$keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`~!@#$%^&*()-=_+[]{}\ \/|?;:\'\",.') { $str = ''; $max = mb_strlen($keyspace, '8bit') - 1; if ($max