如何更新firebase数据

时间:2016-04-26 13:14:03

标签: php firebase firebase-realtime-database

如何在firebase数据库中更新status = 0,其中status = 1。

我试过的是:

<?php
require __DIR__.'/vendor/autoload.php';
use Kreait\Firebase\Configuration;
use Kreait\Firebase\Firebase;
$firebase = new Firebase('LINK', $configuration);
$users = $firebase->get('/users');
for ($i=0; $i < count($users) ; $i++) {
    $data = array('status' => '0');
    $nodeUpdateContent = $firebase->update(['status' => '1'],$users[$i].'/presence/status');
    print_r($nodeUpdateContent);
}
?>

但是当我在firebase数据库中看到它时,它没有更新任何东西。为什么这样?

我关注此链接:Firebase-php

使用以下链接更新数据:Update-data

我进入$users

<?php
[1] => Array
(
    [presence] => Array
    (
        [loginTimestamp] => 1460117596561
        [status] => 1
    )

)

[2] => Array
(
    [presence] => Array
    (
        [loginTimestamp] => 1460117596561
        [status] => 1
    )
)

[3] => Array
(
    [presence] => Array
    (
        [loginTimestamp] => 1460117596561
        [status] => 1
    )
)

?>

我得到了回复:
$ nodeUpdateContent = $ firebase-&gt; update([&#39; status&#39; =&gt;&#39; 1&#39;],$用户[$ i]于&#39; /存在/状态&#39);

Array
(
    [status] => 1
)
Array
(
    [status] => 1
)
Array
(
    [status] => 1
)
Array
(
    [status] => 1
)
Array
(
    [status] => 1
)

It is just printing the status which value is 1, but not updating it.

编辑:

getting error here: Array to string conversion --> $nodeUpdateContent = $firebase->update(['status' => '1'],$users[$i].'/presence/status');

1 个答案:

答案 0 :(得分:0)

请查看我创建的以下git

  

https://github.com/eldhosemjoy/firebase

根据上面的git,

$updated_json = array(
                    "loginTimestamp" => 1460117596561,
                    "status" => 2,
                 );

这是在第一个位置更新

$fboject->path = "/users/1";
$fboject->updateData($updated_json);