Adding a new user to MQTT chat is done in two steps: first define user basic informations in post array. Then add him to your domain users using add function.
PHP
1
require_once vendor/autoload.php;
2
$users=newtelifoun\mqttchat\users();
3
$post_array=array("userid"=>1,
4
"name"=>"foulen",
5
"surname"=>"ben foulen",
6
"profile_link"=>"",
7
"avatar_link"=>"",
8
"gender"=>telifoun\mqttchat\users::MALE);
9
$result=$users->add($post_array);
10
Copied!
1
{
2
"ok":true,
3
"data":{
4
"userid":1
5
}
6
}
Copied!
Update User Informations
To edit existing user information’s, you should define the userid , informations to update then call update function.
PHP
1
require_once vendor/autoload.php;
2
$users=newtelifoun\mqttchat\users();
3
$userid=1;
4
$post_array=array("name"=>"new name");
5
$result=$users->update($userid,$post_array);
Copied!
1
{
2
"ok":true,
3
"data":{
4
"name":"new name"
5
}
6
}
Copied!
Get User Informations
To verify that user information’s are changed, you can use get function. Do not forget to specify userid.
PHP
1
require_once vendor/autoload.php;
2
$users=newtelifoun\mqttchat\users();
3
$userid=1;
4
$result=$users->get($userid);
Copied!
1
{
2
"ok":true,
3
"data":{
4
"userid":1,
5
"name":"new name",
6
"surname":"ben foulen",
7
"gender":0,
8
"avatar_link":"",
9
"profile_link":"",
10
"status":"offline",
11
"timestamp":1607866409
12
}
13
}
Copied!
Delete user
If you want to delete a user, the delete function is made for that.
PHP
1
require_once vendor/autoload.php;
2
$users=newtelifoun\mqttchat\users();
3
$userid=1;
4
$result=$users->delete($userid);
Copied!
1
{
2
"ok":true,
3
"data":{
4
"userid":1
5
}
6
}
Copied!
Get All Users
You can get all users of your domain in groups of 100 users max. You can also filter them by presence status and/or by gender.