尝试向我的类中的 MySQL 发送第二个查询时出错


error when try to send second query to mysql in my class

我有这段代码,但是当我尝试对数据库进行第二次查询时,它崩溃了,为什么?这是代码的一部分,它崩溃的地方

if ($this->doRegister === true) {
        $db = DB::connect();
        $stmt = $db->prepare('SELECT `user_id` FROM `users` WHERE `user_name` = ? OR `user_email` = ? LIMIT 1');
        $stmt->bind_param('ss', $this->store['userData']['name'], $this->store['userData']['email']);
        $stmt->execute();
        $stmt->bind_result($userId);
        $stmt->fetch();
        if (is_numeric($userId)) {
            $stmt = $db->prepare('INSERT INTO `users`(`user_name`, `user_password`, `user_email`, `user_ip`, `user_dateRegistered`, `user_type`) VALUES (?, ?, ?, ?, ?, ?)');
            $hashedPassword = $this->encrytion('md5', md5($this->store['userData']['name']) . md5($this->store['userData']['password']));
            $dateRegistered = time();
            $type = 1;
            $stmt->bind_param('ssssii', $this->store['userData']['name'], $hashedPassword, $this->store['userData']['email'], $_SERVER['REMOTE_ADDR'], $dateRegistered, $type);
            $stmt->execute();
            $this->registerUser();
        } else {
            return array('register' => 'User name or email already exists');
        }
    } else {
        return $this->store['userDataState'];
    }

在执行/准备新查询之前,您需要关闭它。

$stmt->close();