Last active
August 29, 2015 14:22
-
-
Save beccam/89da97681a4eb5c31e29 to your computer and use it in GitHub Desktop.
GettingStartedTwo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$cluster = Cassandra::cluster() | |
->withPersistentSessions(true) | |
->withTokenAwareRouting(true) | |
->build(); | |
$keyspace = 'killrvideo'; | |
$session = $cluster->connect($keyspace); | |
$timestamp = new Cassandra\Timestamp(); | |
$data = array( | |
array(new Cassandra\Uuid('14c532ac-f5ae-479a-9d0a-36604732e01d'), $timestamp, '[email protected]', 'Luke', 'Tillman'), | |
array(new Cassandra\Uuid('dbd29e70-a78c-4bd9-9f90-cb74412875b1'), $timestamp, '[email protected]', 'Jon', 'Haddad') | |
); | |
$insert = $session->prepare("INSERT INTO users (userid, created_date, email, firstname, lastname) | |
VALUES (?, ?, ?, ?, ?)"); | |
foreach ($data as $arguments) { | |
$result = $session->execute($insert, new Cassandra\ExecutionOptions(array('arguments' => $arguments))); | |
} | |
foreach ($result as $row) { | |
printf("user: \"%s\" \"%s\" email: \"%s\" \n", $row['firstname'], $row['lastname'], $row['email']); | |
} | |
$result = $session->execute(new Cassandra\SimpleStatement('SELECT firstname, lastname, email FROM killrvideo.users')); | |
foreach ($result as $row) { | |
printf("user: \"%s\" \"%s\" email: \"%s\" \n", $row['firstname'], $row['lastname'], $row['email']); | |
} | |
$data = array( | |
array('[email protected]', new Cassandra\Uuid('14c532ac-f5ae-479a-9d0a-36604732e01d')), | |
array('[email protected]', new Cassandra\Uuid('dbd29e70-a78c-4bd9-9f90-cb74412875b1')) | |
); | |
$update = $session->prepare('UPDATE users SET email = ? WHERE userid = ?'); | |
foreach ($data as $arguments) { | |
$futures[] = $session->executeAsync($update, new Cassandra\ExecutionOptions(array('arguments' => $arguments))); | |
} | |
foreach ($futures as $future) { | |
$future->get(5); | |
} | |
$result = $session->execute(new Cassandra\SimpleStatement('SELECT firstname, lastname, email FROM killrvideo.users ')); | |
foreach ($result as $row) { | |
printf("user: \"%s\" \"%s\" email: \"%s\" \n", $row['firstname'], $row['lastname'], $row['email']); | |
} | |
$delete = $session->prepare('DELETE FROM users WHERE userid = ? '); | |
$session->execute($delete, new Cassandra\ExecutionOptions(array( | |
'arguments' => array | |
(new Cassandra\Uuid('14c532ac-f5ae-479a-9d0a-36604732e01d')) | |
)) | |
); | |
$select = $session->prepare(new Cassandra\SimpleStatement('SELECT firstname, lastname, email FROM users WHERE userid = ? ')); | |
$result = $session->execute($select, new Cassandra\ExecutionOptions(array( | |
'arguments' => array | |
(new Cassandra\Uuid('14c532ac-f5ae-479a-9d0a-36604732e01d')) | |
)) | |
); | |
foreach ($result as $row) { | |
printf("user: \"%s\" \"%s\" email: \"%s\" \n", $row['firstname'], $row['lastname'], $row['email']); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment