I have a Firebase store, contains two data fields
-imagineeringuk
-- data
----temperature
----humidity
And I am using the kreait sdk. Nothing wrong with the SDK I might add, just me.
I don't seem to be able to get any data to come back from the realtime db, so I am here asking for help once more.
I have an index.php (redacted to remove all the guff).
<?php
include('dbcon.php');
$ref = "imagineeringuk";
$getdata = $database->getReference($ref)->getValue();
$i = 0;
if($getdata > 0)
{
foreach($getdata as $key => $row)
{
$i ;
?>
<tr>
<td><?php echo $row['temperature']; ?></td>
<td><?php echo $row['humidity']; ?></td>
<td>
<a href="edit.php?token=<?php echo $key; ?>" class="btn btn-primary">Edit</a>
</td>
<td>
<form action="code.php" method="POST">
<input type="hidden" name="ref_token_delete" value="<?php echo $key; ?>">
<button type="submit" name="delete_data" class="btn btn-danger">Delete</button>
</form>
</td>
</tr>
<?php
}
}
else
{
?>
<tr class="text-center">
<td colspan="6">DATA NOT THERE IN DATABASE</td>
</tr>
<?php
}
?>
And the dbcon.php file here ...
<?php
require __DIR__.'/vendor/autoload.php';
use Kreait\Firebase\Factory;
use Kreait\Firebase\ServiceAccount;
// This assumes that you have placed the Firebase credentials in the same directory
// as this PHP file.
$factory = (new Factory)->withServiceAccount(__DIR__.'/imagineXXXXXXXXXXXXXXXXXXXXXX.json');
$database = $factory->createDatabase();
?>
Does anyone have any idea what Im missing here?
CodePudding user response:
You seem to be passing the name of your database (imagineeringuk
) to getReference()
. Instead you pass the DB name during initialization (withDatabaseUri
) and then either pass the path within the database you want to get, or nothing, to getReference()
.