1

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

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'];
    }
4

1 回答 1

1

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

$stmt->close();
于 2012-04-14T21:15:01.830 回答