Skip to content

PHP Library for accessing google spreadsheet content via SheetDB. https://sheetdb.io

Notifications You must be signed in to change notification settings

sheetdb/sheetdb-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 

Repository files navigation

PHP SheetDB Class

Installation

The SheetDB PHP Library is available through Composer

composer require sheetdb/sheetdb-php

Test spreadsheet

At any time you can play with our test API here: https://sheetdb.io/api/v1/58f61be4dda40

You can also go to Google Sheets and play with it: https://docs.google.com/spreadsheets/u/2/d/1mrsgBk4IAdSs8Ask5H1z3bWYDlPTKplDIU_FzyktrGk/edit The spreadsheet resets every hour.

Basic usage

In order to instantiate SheetDB connection you need to give an api id. You can find it in SheetDB Dashboard.

require('vendor/autoload.php');
use SheetDB\SheetDB;

$sheetdb = new SheetDB('58f61be4dda40');
$response = $sheetdb->get(); // returns all spreadsheets data
$response = $sheetdb->keys(); // returns all spreadsheets key names
$response = $sheetdb->name(); // returns name of a spreadsheet document

Searching

You can use search method to find only specific rows. You have 2 options. Search rows that meets all of the conditions or search rows that meets at least one of the conditions.

You can use second parameter if you want the search to be case sensitive (it is boolean). By default it is not case sensitive.

$response = $sheetdb->search(['name'=>'Steve','age'=>'22']); // returns when name="Steve" AND age=22
$response = $sheetdb->searchOr(['name'=>'Steve','age'=>'19']); // returns when name="Steve" OR age=19

$response = $sheetdb->search(['name'=>'Steve'], true); // returns when name="Steve", this query is case sensitive

Creating a row(s)

If you want to create a new row you'll need to pass an array with key_name => value. If you want to create multiple rows that should be an array of arrays.

$sheetdb->create(['name'=>'Mark','age'=>'35']);
$sheetdb->create([
	['name'=>'Chris','age'=>'34'],
	['name'=>'Amanda','age'=>'29'],
]);

Updating a row(s)

First two parameters are key and value that need to match, third argument is array similar to the create one.

Fourth parameter is optional. If it's true not specified values will be emptied.

$sheetdb->update('name','Chris',['age'=>'33']); // it will change only age
$sheetdb->update('name','Chris',['age'=>'33'],true); // it will update age to 33 but all other values will be emptied, in this case a name

Update the batch of rows in the spreadsheet

Update for various queries. First argument is data itself. Each object in it should have a query key with the actual query (for example, "id=5"), and the remaining keys will be updated, as in a regular PATCH / PUT request.

Second parameter is optional. If it's true not specified values will be emptied.

$sheetdb->batchUpdate([
    [
        'query' => 'id=1',
        'age' => '33',
    ],
    [
        'query' => 'id=2',
        'age' => '52',
    ]
]);

Delete a row(s)

Just like in update first two parameters are key and value. Every row that will match query will be deleted.

$sheetdb->delete('name','Chris'); // will delete all rows with name = "Chris"

About

PHP Library for accessing google spreadsheet content via SheetDB. https://sheetdb.io

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages