PHP code example of ldubois / php-airtable

1. Go to this page and download the library: Download ldubois/php-airtable library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ldubois / php-airtable example snippets


$key   = "APP_KEY"; // Generated from : https://airtable.com/account
$base  = "BASE_ID"; // Find it on : https://airtable.com/api
$table = "TABLE_NAME"; // Find it on : https://airtable.com/api

$airtable = new Airtable($key, $base);

$records = $airtable->findRecords($table);

$key   = "APP_KEY"; // Generated from : https://airtable.com/account
$base  = "BASE_ID"; // Find it on : https://airtable.com/api
$table = "TABLE_NAME"; // Find it on : https://airtable.com/api

$airtable = new Airtable($key, $base);

$records = $airtable->findRecords($table);

use Ldubois\AirtableSDK\Airtable as AirtableClient;

class MemberIndex
{
    private $airtable;

    public function __construct(AirtableClient $airtableClient, string $table)
    {
        $this->airtable = $airtableClient->createTableManipulator($table);
    }

    public function clear()
    {
        $this->airtable->flushRecords();
    }

    public function search(){
        $records  =  $this->airtable->searchRecords( ["Champ1","Champ2"], "search_value");
        return $records;
    }

    public function save(array $data)
    {
        $criteria = ["Id" => $data["id"]];
        $fields   = [
            "Id"                    => $data["id"],
            "Firstname"             => $data["firstName"],
            "Lastname"              => $data["lastName"],
            "Email"                 => $data["email"],
            "CreatedAt"             => (string)$data["createdAt"],
        ];

        if ($this->airtable->containsRecord($criteria)) {
            $this->airtable->updateRecord($criteria, $fields);
        } else {
            $this->airtable->createRecord($fields);
        }
    }

    public function delete($id)
    {
        $this->airtable->deleteRecord(["Id" => $id]);
    }
}
 bash
composer