RSS

How to fetch data from AWS Athena using PHP

// https://aws.amazon.com/documentation/sdk-for-php/

require_once ‘aws/aws-autoloader.php’;

use Aws\Athena\AthenaClient;

try {
$Client = AthenaClient::factory(array(
‘version’ => ‘latest’,
‘region’ => ‘REGION’,
‘credentials’ => array(
‘key’ => ‘KEY’,
‘secret’ => ‘SECRET_KEY’,
)
));

$result1 = $Client->StartQueryExecution(
array(
“QueryExecutionContext”=> array( “Database”=> “DB_NAME” ),
“QueryString”=> “SELECT * FROM TABLE_NAME”,
“ResultConfiguration”=> array(
“EncryptionConfiguration”=> array(“EncryptionOption”=> “SSE_S3”),
“OutputLocation”=> “S3 Path” // like s3://BUCKET_NAME/FOLDER_PATH
)
)
);

// wait till query execution complete on Athena
while(1)
{
$result = $Client->getQueryExecution(array(‘QueryExecutionId’ => $result1->get(‘QueryExecutionId’)));
$res = $result->toArray();

if($res[‘QueryExecution’][‘Status’][‘State’]==’FAILED’)
{
echo ‘Query Failed’;
die;
}
else if($res[‘QueryExecution’][‘Status’][‘State’]==’CANCELED’)
{
echo ‘Query was cancelled’;
die;
}
else if($res[‘QueryExecution’][‘Status’][‘State’]==’SUCCEEDED’)
{
break; // break while loop
}

}

$result1 = $Client->GetQueryResults(array(
‘QueryExecutionId’ => $result1->get(‘QueryExecutionId’) // REQUIRED
));

echo ‘<pre>’;
print_r($result1);
echo ‘</pre>’;
die;

}
catch (AthenaException $e) {
// Catch an S3 specific exception.
echo $e->getMessage();
} catch (AwsException $e) {
// This catches the more generic AwsException. You can grab information
// from the exception using methods of the exception object.
echo $e->getAwsRequestId() . “\n”;
echo $e->getAwsErrorType() . “\n”;
echo $e->getAwsErrorCode() . “\n”;
}

 
Leave a comment

Posted by on July 20, 2017 in Athena, AWS

 

Tags: , , ,

How to check mod_rewrite ingine is installed or not

using phpinfo(); –> find mod_rewrite

In order to use mod_rewrite you can type the following command in the terminal:

a2enmod rewrite

service apache2 restart

 
Leave a comment

Posted by on December 14, 2015 in Apache

 

Sort array on multiple columns

<?php

$sorted = array_orderby($data, ‘col1’, SORT_ASC, ‘col2’, SORT_ASC);

function array_orderby() {
$args = func_get_args();
$data = array_shift( $args );

if ( ! is_array( $data ) ) {
return array();
}

$multisort_params = array();
foreach ( $args as $n => $field ) {
if ( is_string( $field ) ) {
$tmp = array();
foreach ( $data as $row ) {
$tmp[] = $row[ $field ];
}
$args[ $n ] = $tmp;
}
$multisort_params[] = &$args[ $n ];
}

$multisort_params[] = &$data;

call_user_func_array( ‘array_multisort’, $multisort_params );
return end( $multisort_params );
}

?>

 
Leave a comment

Posted by on October 11, 2014 in Core PHP

 

Tags: ,

How to refresh a parent window when Joomla modal popup box is closed?

In your anchor tag please add below code:

rel=”{size: {x: popupwidth, y: popupheight}, handler:’iframe’,onClose:function(){var js =window.location.reload();}}”

 
Leave a comment

Posted by on September 19, 2014 in Joomla

 

How to get all selected checkboxes VALUES in jquery

var checkedValues = $(‘input:checkbox:checked’).map(function() {
return this.value;
}).get();

 
Leave a comment

Posted by on September 12, 2014 in jQuery

 

How to Select / Deselect All Checkboxes using jQuery

jQuery('#checkAll').click(function(){    
    jQuery(':checkbox.checkItem').prop('checked',this.checked);
});
 
Leave a comment

Posted by on June 20, 2014 in jQuery

 

php text to speech with google api

<?php
// Convert Words (text) to Speech (MP3)
// ————————————
$word= “Your text here”;
// Google Translate API cannot handle strings > 100 characters
$word = substr($word, 0, 100);

// Replace the non-alphanumeric characters
// The spaces in the sentence are replaced with the Plus symbol
$word = urlencode($word);

// If the MP3 file exists, do not create a new request
// create curl resource
$ch = curl_init();

// set url
curl_setopt($ch, CURLOPT_URL, ‘http://translate.google.com/translate_tts?ie=UTF-8&tl=en&q=&#8217;.$word);

//return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

// $output contains the mp3 file
$mp3 = curl_exec($ch);

// close curl resource to free up system resources
curl_close($ch);

file_put_contents(‘temp.mp3’, $mp3);
?>

 
Leave a comment

Posted by on October 28, 2013 in Core PHP

 

Tags: ,