mysqli准备好的声明没有运行

时间:2014-10-18 01:46:18

标签: php mysqli

遇到mysqli准备好的声明问题。我的功能是假设在我的数据库中创建一个新雇主但是当我删除api_key参数时,该语句不再起作用。有什么问题?

public function createEmployer($companyName, $email, $password, $confirmPass) {

    $response = array ();

    // First check if user already existed in db
    if (! $this->isEmpExists ( $email )) {



        if ($this->comparePassword ( $password, $confirmPass )) {

            // Generating password hash
            $password_hash = PassHash::hash ( $password );

            // Generating API key
            $api_key = $this->generateApiKey ();

            // insert query
            $stmt = $this->conn->prepare ( "INSERT INTO company(name, email, password, api_key) values(?, ?, ?, ?)" );
            $stmt->bind_param ( "ssss", $companyName, $email, $password_hash, $api_key);

            $result = $stmt->execute ();

            $stmt->close ();

            // Check for successful insertion
            if ($result) {
                // User successfully inserted
                return USER_CREATED_SUCCESSFULLY;
            } else {
                // Failed to create user
                return USER_CREATE_FAILED;
            }
        } else {
            return PASSWORDS_DO_NOT_MATCH;
        }
    } else {
        // User with same email already existed in the db
        return USER_ALREADY_EXISTED;
    }

    return $response;
}

一旦我删除了像这样的api_key参数

public function createEmployer($companyName, $email, $password, $confirmPass) {

    $response = array ();

    // First check if user already existed in db
    if (! $this->isEmpExists ( $email )) {



        if ($this->comparePassword ( $password, $confirmPass )) {

            // Generating password hash
            $password_hash = PassHash::hash ( $password );

            // Generating API key
            $api_key = $this->generateApiKey ();

            // insert query
            $stmt = $this->conn->prepare ( "INSERT INTO company(name, email, password) values(?, ?, ?)" );
            $stmt->bind_param ( "sss", $companyName, $email, $password_hash);

            $result = $stmt->execute ();

            $stmt->close ();

            // Check for successful insertion
            if ($result) {
                // User successfully inserted
                return USER_CREATED_SUCCESSFULLY;
            } else {
                // Failed to create user
                return USER_CREATE_FAILED;
            }
        } else {
            return PASSWORDS_DO_NOT_MATCH;
        }
    } else {
        // User with same email already existed in the db
        return USER_ALREADY_EXISTED;
    }

    return $response;
}

该函数返回USER_CREATE_FAILED

0 个答案:

没有答案