Added code to print out the inserted data, and to check if the data was inserted by querying the database for the inserted data

master
Aadhavan Srinivasan 2 years ago
parent c81937d6a5
commit 92b70e632b

@ -11,20 +11,32 @@ $shortlink = $_GET["glink"];
$session = $cluster->connect($keyspace); $session = $cluster->connect($keyspace);
//$statement = new Cassandra\SimpleStatement('SELECT name FROM data WHERE id=5'); //$statement = new Cassandra\SimpleStatement('SELECT name FROM data WHERE id=5');
$rand_num = rand(0,999999); $rand_num = rand(0,99999999);
$values = array( $values = array(
'id' => $rand_num, 'id' => $rand_num,
'url' => $url, 'url' => $url,
'shortlink' => $shortlink, 'shortlink' => $shortlink,
); );
$statement = new Cassandra\SimpleStatement('INSERT INTO data (id, url, shortlink, when_created) VALUES (?,?,?,toTimestamp(now()))'); $statement = new Cassandra\SimpleStatement('INSERT INTO data (id, url, shortlink, when_created) VALUES (?,?,?,toTimestamp(now()))');
$options = array('arguments' => $values); $options = array('arguments' => $values);
$result = $session->execute($statement,$options);
$statement = new Cassandra\SimpleStatement('SELECT url,shortlink FROM data WHERE id=?');
$options = array('arguments' => array('id' => $rand_num));
$result = $session->execute($statement,$options);
//$stringRepresentation= json_encode($result[0]);
$future = $session->executeAsync($statement,$options); //printf("%s\n\n\n",$stringRepresentation);
$result = $future->get();
printf('Successful'); foreach($result as $row) {
if (is_null($row)) {
printf('Unsuccessful');
} else {
printf('Successful: The URL you entered was: %s and your GLink is: https://glink.zip/%s', $row['url'],$row['shortlink']);
}
}
//printf('Done');
?> ?>

Loading…
Cancel
Save