PHP code example of zenghuaming / presto-php-client

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

    

zenghuaming / presto-php-client example snippets




use Clouding\Presto\Presto;

$presto = new Presto();

$presto->addConnection([
    'host' => 'localhost:8080',
    'catalog' => 'default',
    'schema' => 'presto',
]);

// Set manager as global (optional)
$presto->setAsGlobal();



$posts = $presto->connection()->query('select * from posts')->get();



$posts = Presto::query('SELECT * FROM posts')->get();
/* 
    [
        [1, 'Good pracetice'],
        [2, 'Make code cleaner'],
    ]
*/

$posts = Presto::query('SELECT * FROM posts')->getAssoc();
/* 
    [
        ['id' => 1, 'title' => 'Good pracetice'],
        ['id' => 2, 'title' => 'Make code cleaner'],
    ]
*/    



use Clouding\Presto\Presto;

$presto = new Presto();

$presto->addConnection([
    'host' => 'localhost:8080',
    'catalog' => 'default',
    'schema' => 'presto',
]);

$presto->addConnection([
    'host' => 'localhost:8080',
    'catalog' => 'default2',
    'schema' => 'presto2',
], 'presto2');

$presto->setAsGlobal();

// Get connections
$connections = Presto::getConnections();

// Specify connection
$posts = Presto::query('SELECT * FROM posts', 'presto2')->getAssoc();

composer