PHP code example of campoint / postgrest-php

1. Go to this page and download the library: Download campoint/postgrest-php 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/ */

    

campoint / postgrest-php example snippets



    $clientAuthConfig = new ClientAuthConfig(
        authArguments: [
            'email' => '[email protected]',
            'pass' => 'password',
        ],
    );
    $client = new PostgrestSyncClient(
        'http://localhost:8080',
        5,
        clientAuthConfig: $clientAuthConfig
    );
    try {
        $client->auth();
    } catch (FailedAuthException $e) {
       // do something
    }

Async
^^^^^

Create a client for asynchronous environments:

.. code:: php

    $clientAuthConfig = new ClientAuthConfig(
        authArguments: [
            'email' => '[email protected]',
            'pass' => 'password',
        ],
    );
    $client = new PostgrestAsyncClient(
        'http://localhost:8080',
        5,
        (new Browser(null, $loop)),
        $clientAuthConfig
    );
    $client->auth()->then(
        function () {
            // do something on success
        },
        function (FailedAuthException $e) {
            // do something on rejection
        }
    )


    $response = $client->run(
        $client->from('schema_name', 'table_name')
            ->select('column_a', 'column_b')
            ->eq('column_c', 'foo')
            ->gt('column_d', 0.5)
            ->in('column_e', 1, 2, 3)
    )


    $response = $client->run(
        $client->from('schema_name', 'table_name')
            ->insert(
                [
                    [
                        'column_a' => 'foo'
                    ],
                    [
                        'column_a' => 'bar'
                    ]
                ]
            )
    )


    $response = $client->run(
        $client->from('schema_name', 'table_name')
            ->upsert(
                [
                    [
                        'column_a' => 'foo'
                    ],
                    [
                        'column_a' => 'bar'
                    ]
                ],
                duplicateResolution: DuplicateResolution::MERGE
            )
    )


    $response = $client->run(
        $client->from('schema_name', 'table_name')
            ->update(['column_a' => 'foo'])
            ->eq('column_a', 'bar')
    )


    $response = $client->run(
        $client->from('schema_name', 'table_name')
            ->delete()
            ->eq('column_a', 'bar')
    )


    $response = $client->call(
        'foobar',
        [
            'arg1' => 'foo',
            'arg2' => 'bar'
        ],
        'schema_name'
    )