0

我正在尝试从下面的代码中获取输出“连接 %d 将消息“%s”发送到 %d 个其他连接%s”:

public function onMessage(ConnectionInterface $from, $msg) {
    $db = new DbConnect;
    $DBconn = $db->connect();

    $numRecv = count($this->clients) - 1;
    echo sprintf('Connection %d sending message "%s" to %d other connection%s' . "\n"
        , $from->resourceId, $msg, $numRecv, $numRecv == 1 ? '' : 's');

    $data = json_decode($msg);

    $id_receiver = 0;
    $message = "";
    if($data->id_receiver!=0){
        $id_receiver = $data->id_receiver;
        $message = $data->msg_data;
    }

    $stmt = $DBconn->prepare("SELECT last_connection FROM users where id=?");
    $stmt->bind_param("i", $id_receiver);
    $stmt->execute();
    $stmt->bind_result($lastConUser);
    $stmt->fetch();
    echo $lastConUser;


    if($lastConUser>0){
        $this->clients[$lastConUser]->send($message);
    }

}
}

但相反,我得到了这样的错误:

在此处输入图像描述

第 85 行是这个代码:

 if($lastConUser>0){
        $this->clients[$lastConUser]->send($message);
    }
4

0 回答 0