Php - 调用成员函数fetch_assoc()

First I was have:

 public function getAllUserTasks($user_id) {
        $stmt = $this->conn->prepare("SELECT t.* FROM tasks t, user_tasks ut WHERE t.id = ut.task_id AND ut.user_id = ?");
        $stmt->bind_param("i", $user_id);
        $stmt->execute();
        $stmt->bind_result();
        $tasks = $stmt->get_result();
        $stmt->close();
        return $tasks;
    }

and this function have a problem with get_result() so instead get_result now I write function with BIND and FETCH:

public function getAllUserTasks($user_id) {
        $stmt = $this->conn->prepare("SELECT t.* FROM tasks t, user_tasks ut WHERE t.id = ut.task_id AND ut.user_id = ?");
        $stmt->bind_param("i", $user_id);
        $stmt->execute();
        $tasks = array();
            $stmt->bind_result($id, $task, $status, $created_at);

            $stmt->fetch();
            $tasks["id"] = $id;
            $tasks["task"] = $task;
            $tasks["status"] = $status;
            $tasks["created_at"] = $created_at;
            $stmt->close();
            return $tasks;
    }

But on other file index.php now I get:<b>Fatal error</b>: Call to a member function fetch_assoc() on a non-object in <b>/home/agroagro/public_html/agroMobile/v1/index.php</b> on line <b>155</b><br />

so there is a code:

$app->get('/tasks', 'authenticate', function() {
            global $user_id;
            $response = array();
            $db = new DbHandler();

            // fetching all user tasks
            $result = $db->getAllUserTasks($user_id);

            $response["error"] = false;
            $response["tasks"] = array();

            // looping through result and preparing tasks array
            while ($task = $result->fetch_assoc()) {    <--HERE IS LINE 155 and ERROR
                $tmp = array();
                $tmp["id"] = $task["id"];
                $tmp["task"] = $task["task"];
                $tmp["status"] = $task["status"];
                $tmp["createdAt"] = $task["created_at"];
                array_push($response["tasks"], $tmp);
            }

            echoRespnse(200, $response);
        });

I try to solve this all day and dont work... Can somebody tell me what is exactly the problem here now?

What is the problem with this code?

Something like this (untested code):

public function getAllUserTasks($user_id) {
    $stmt = $this->conn->prepare("SELECT t.* FROM tasks t, user_tasks ut WHERE t.id = ut.task_id AND ut.user_id = ?");
    $stmt->execute(array($user_id));

    return $stmt->fetchAll(PDO::FETCH_ASSOC);
}

$app->get('/tasks', 'authenticate', function() {
    global $user_id;
    $response = array();
    $db = new DbHandler();

    $response["error"] = false;
    $response["tasks"] = $db->getAllUserTasks($user_id);

        echoRespnse(200, $response);
    });