PHP code example of neighborhoods / snowflake-sql-api-component

1. Go to this page and download the library: Download neighborhoods/snowflake-sql-api-component 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/ */

    

neighborhoods / snowflake-sql-api-component example snippets

 php
use Neighborhoods\SnowflakeSqlApiComponent\SingleStatementClientV1;

/** @var SingleStatementClientV1\ClientInterface $client */
$rows = $client->execute("SELECT 'Hello World!' as text_field, 1 as int_field");
foreach ($rows as $row) {
    foreach ($row as $columnName => $columnValue) {
        echo $columnName . ': ' . $columnValue . PHP_EOL;
    }
}
 php
use Neighborhoods\SnowflakeSqlApiComponent\SingleStatementClientV1;

/** @var SingleStatementClientV1\ClientInterface $client */
$rows = $client->execute("SELECT CONCAT('Hello ', ?, '!') as \"text_field\", ? as \"int_field\"", ['Again', 5]);
foreach ($rows as $row) {
    foreach ($row as $columnName => $columnValue) {
        echo $columnName . ': ' . $columnValue . PHP_EOL;
    }
}
 php
use Neighborhoods\SnowflakeSqlApiComponent\SingleStatementClientV1;

/** @var SingleStatementClientV1\ClientInterface $client */
$generator = $client->executePaginated("
WITH RECURSIVE NumberSequence (n, long_text_field) AS (
  SELECT 1 AS n, 'Lorem ipsum dolor sit amet' as long_text_field
  UNION ALL
  SELECT n + 1, concat(long_text_field, ', Lorem ipsum dolor sit amet') FROM NumberSequence WHERE n < 100000 
)
SELECT n FROM NumberSequence ORDER BY n");

foreach ($generator as $page) {
    echo 'Page starts with ' . $page[0]['N'] . ' and ends with ' . end($page)['N'] . PHP_EOL;
}
 php
use Neighborhoods\SnowflakeSqlApiComponent\SingleStatementClientV1;

/** @var SingleStatementClientV1\ClientInterface $client */
$client = $container->get(SingleStatementClientV1\ClientInterface::class);
$client->setClientV1JwtTokenGenerator($jwtTokenGenerator);
 php
use Neighborhoods\SnowflakeSqlApiComponent\ClientV1;

$jwtTokenGenerator = (new ClientV1\JwtTokenGenerator())
    ->setAccount('snowflake_account')
    ->setUser('snowflake_user')
    ->setPrivateKey(file_get_contents('~/path/snowflake_private_key.pem'));