Skip to content

Instantly share code, notes, and snippets.

@beccam
Created May 26, 2015 16:20
Show Gist options
  • Save beccam/1efc9b5eb1d3553cca57 to your computer and use it in GitHub Desktop.
Save beccam/1efc9b5eb1d3553cca57 to your computer and use it in GitHub Desktop.
Getting Started with Apache Cassandra and PHP
<?php
$cluster = Cassandra::cluster()
->build();
$keyspace = 'killrvideo';
$session = $cluster->connect($keyspace);
$statement = $session->execute(new Cassandra\SimpleStatement(
"INSERT INTO users (userid, created_date, email, firstname, lastname) VALUES (14c532ac-f5ae-479a-9d0a-36604732e01d, '2013-01-01 00:00:00', '[email protected]','Luke','Tillman')"
));
$result = $session->execute(new Cassandra\SimpleStatement("SELECT firstname, lastname, email FROM killrvideo.users WHERE userid=14c532ac-f5ae-479a-9d0a-36604732e01d"));
foreach ($result as $row) {
printf("user: \"%s\" \"%s\" email: \"%s\" .\n", $row['firstname'], $row['lastname'], $row['email']);
}
$update = $session->execute(new Cassandra\SimpleStatement("UPDATE users SET email = '[email protected]' WHERE userid = 14c532ac-f5ae-479a-9d0a-36604732e01d"));
$result = $session->execute(new Cassandra\SimpleStatement("SELECT firstname, lastname, email FROM killrvideo.users WHERE userid=14c532ac-f5ae-479a-9d0a-36604732e01d"));
foreach ($result as $row) {
printf("user: \"%s\" \"%s\" email: \"%s\" .\n", $row['firstname'], $row['lastname'], $row['email']);
}
$delete = $session->execute(new Cassandra\SimpleStatement("DELETE FROM users WHERE userid = 14c532ac-f5ae-479a-9d0a-36604732e01d"));
$result = $session->execute(new Cassandra\SimpleStatement("SELECT firstname, lastname, email FROM killrvideo.users WHERE userid=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