MySQLi使用Multi WHERE子句准备SELECT显示affected_rows -1

时间:2016-11-18 20:53:11

标签: mysql

$stmt = $this->conn->prepare("SELECT `ticket_number`, `name`, `division`, `position`, `email`, `contact`, `date`, `request_title`, `description`, `status`, `category`, `priority` FROM `ticket_problem` WHERE `ticket_number` = ?");
        $stmt->bind_param("s", $ticket_number);
        if($stmt->execute()){
        $stmt->bind_result($ticket_number,$name,$division,$position,$email,$contact,$date,$request_title,$description,$status,$category,$priority);
                         $tmp = array();
                         while($stmt->fetch()){
                              $user = array();
                              $user['ticket_number'] = $ticket_number;
                              $user['name'] = $name;
                              $user['division'] = $division;
                              $user['position'] = $position;
                              $user['email'] = $email;
                              $user['contact'] = $contact;
                              $user['date'] = $date;
                              $user['request_title'] = $request_title;
                              $user['description'] = $description;
                              $user['status'] = $status;
                              $user['category'] = $category;
                              $user['priority'] = $priority;

                              array_push($tmp,$user);
                         }  
                    $stmt->close();
                    return $user;
                    }

该代码运行良好,但另一方面如下:

if($stmt = $this->conn->prepare("SELECT `ticket_number`, `name`, `division`, `position`, `email`, `contact`, `date`, `request_title`, `description`, `status`, `category`, `priority` FROM `ticket_problem` WHERE `ticket_number` = ? AND `email`=?")){
        $stmt->bind_param("ss", $ticket_number,$email);
        $stmt->execute();
        $stmt->bind_result($ticket_number,$name,$division,$position,$email,$contact,$date,$request_title,$description,$status,$category,$priority);
        $tmp = array();
        while($stmt->fetch()){
            $user = array();
            $user['ticket_number'] = $ticket_number;
            $user['name'] = $name;
            $user['division'] = $division;
            $user['position'] = $position;
            $user['email'] = $email;
            $user['contact'] = $contact;
            $user['date'] = $date;
            $user['request_title'] = $request_title;
            $user['description'] = $description;
            $user['status'] = $status;
            $user['category'] = $category;
            $user['priority'] = $priority;

            array_push($tmp,$user);
        }
        $stmt->close();
        return $user;
        }

该代码影响了行-1,$ user未定义。我不知道为什么。该代码相同但我使用的2个查询之间的差异" AND"。这里是完整的代码

public function pendingTicketData($email,$ticket_number){
    var_dump($email,$ticket_number);
    $stmt = $this->conn->prepare("SELECT `ticket_number`,`name`, `email` FROM `ticket_problem` WHERE `email` = ?");
    $stmt->bind_param("s", $email);
    $result = $stmt->execute();
    $stmt->close();

    if(!$result){
        return false;
    }else{
        if($stmt = $this->conn->prepare("SELECT `ticket_number`, `name`, `division`, `position`, `email`, `contact`, `date`, `request_title`, `description`, `status`, `category`, `priority` FROM `ticket_problem` WHERE `ticket_number` = ? AND `email`=?")){
        $stmt->bind_param("ss", $ticket_number,$email);
        $stmt->execute();
        $stmt->bind_result($ticket_number,$name,$division,$position,$email,$contact,$date,$request_title,$description,$status,$category,$priority);
        $tmp = array();
        while($stmt->fetch()){
            $user = array();
            $user['ticket_number'] = $ticket_number;
            $user['name'] = $name;
            $user['division'] = $division;
            $user['position'] = $position;
            $user['email'] = $email;
            $user['contact'] = $contact;
            $user['date'] = $date;
            $user['request_title'] = $request_title;
            $user['description'] = $description;
            $user['status'] = $status;
            $user['category'] = $category;
            $user['priority'] = $priority;

            array_push($tmp,$user);
        }
        $stmt->close();
        return $user;
        }
    }

}

0 个答案:

没有答案