coderatio/phpfirebase

一个简单、干净的 CRUD PHP 库,用于 Google Firebase 数据存储

v1.0 2018-11-27 13:36 UTC

This package is auto-updated.

Last update: 2024-09-28 04:03:37 UTC


README

一个简单、干净的 CRUD PHP 库,用于 Google Firebase 数据存储。此库允许您创建、读取、更新和删除存储在 Google Firebase 数据库中的记录。

安装

要安装库,请执行以下命令:composer require coderatio/phpfirebase:v1.0composer require coderatio/phpfirebase

如何使用

开始使用前,请确保创建一个文件夹并保存您的 Google Firebase 服务账户密钥 json 文件。

创建新记录(C)

要创建新记录,请执行以下操作...

require 'vendor/autoload';
use Coderatio\PhpFirebase\PhpFirebase;

$pfb = new PhpFirebase($pathToSecretKeyJsonFile);
$pfb->setTable('posts');
$pfb->insertRecord([
    'title' => 'Post one',
    'body' => 'Post one contents'
  ], $returnData);
  //The $returnData which is boolean returns inserted data if set to true. Default is false.

读取记录(R)

要读取创建的记录,请执行以下操作...

// Getting all records
$pfb->getRecords();

// Getting a record. Note: This can only be done via the record id.
$pfb->getRecord(1); 

更新记录(U)

要更新记录,请执行以下操作...

// This takes the record ID and any column you want to update.
$pfb->updateRecord(1, [
  'title' => 'Post one edited'
]);

删除记录(D)

要删除创建的记录,请执行以下操作...

 // This takes only the record ID. Deleting all records will be added in Beta-2
 
 $pfb->deleteRecord(1);

贡献

请将仓库分支并发送 pull request,或在 Twitter 上找到我。