Skip to content

Ashishkumbhar01/supabase-php

Repository files navigation

Supabase

GitHub Repo stars Packagist Downloads GitHub Release GitHub License GitHub forks GitHub Sponsors

Supabase client for PHP:

  • Realtime database, Storage, Authentication and many more.
  • When you creating your supabase table, make sure RLS (Row Level Security) option be [×] disable.
  • If RLS are enable [✓] maybe you getting some error so you need to use Auth class. Auth class coming soon.

Install

  • Install Supabase client for our project.
  • Than we are require supabase-client by composer.
composer require supabase-php/supabase-client:"1.0.4"

Config

Supabase client for PHP configuration with your php project/web Apps.

use Supabase\Functions as Supabase;

// autoload the supabase class
require_once('vendor/autoload.php');

// config
$config = [
  'url' => $_ENV['SB_URL'],
  'apikey' => $_ENV['SB_APIKEY']
];

$client = new Supabase($config['url'], $config['apikey']);

if you did not have .env file so please create your .env file.

touch .env

if you create already your .env file then you will be derclare your enviroment variables names.

vi .env
SB_URL=https://rurtighghurtuhouger.supabase.co
SB_API_KEY=utertu895tyut8trrvt8rtu8mutt84r548t894v98v5vtt6ut54uu85tu

getAllData()

if you want to get all recorded data from your table when you saved the data then used getAllData function.

$data = $client->getAllData('table name');
print_r($data);

getSingleData()

if you need a specifics data from specifics columns then you used getSingleData function.

$data = $client->getSingleData('table name', 'column name');
print_r($data);

postData()

if you want to save your data to your table then used postData function.

// posted data
$data = [
  'name' => 'PHP',
  'version' => '8.3'
];

$client->postData('table name', $data);

updateData()

if you thinks something to be wrong or outdated so you will be changing that particular value from particular columns and also you updating all the data. Then used updateData function.

// updated data
$data = [
  'name' => 'PHP',
  'version' => '8.4'
];

$client->updateData('table name', 'id number', $data);

deleteData()

if you want to Delete a specificed data from the table, then used deleteData function. you needed the id number of table data.

$client->deleteData('table name', 2 //id);

Pagination()

$client->pages('table name');

Filtering()

$client->filter('table name', 1);

Matching()

$data = [
  'name' => 'PHP',
  'version' => '8.4'
];

$client->matchs('table name', $data);

Authentication

  • Auth Class coming soon.

Storage

  • storage class coming soon.