How to execute Cassandra query in php using phpcassa ?

504 views
Skip to first unread message

keshab kumar

unread,
Dec 9, 2013, 1:50:42 AM12/9/13
to phpc...@googlegroups.com
<?php 
 ini_set('display_errors',1); 
 error_reporting(E_ALL);
ob_start();

require_once(__DIR__.'/lib/autoload.php');
require_once('phpcassa/connection.php');
require_once "phpcassa/columnfamily.php";

use phpcassa\Connection\ConnectionPool;
use phpcassa\ColumnFamily;
use phpcassa\ColumnSlice;
use phpcassa\SystemManager;
use phpcassa\Schema\StrategyClass;
use phpcassa\Connection\NoServerAvailable;
$pool->get()->client->set_cql_version("3.0.0");

$server = array("127.0.0.1:9160");
$pool = new ConnectionPool("keshab", $server);

$column_family = new ColumnFamily($pool, 'contact');

if(isset($_POST['submit'])){

$Industry=$_POST['Industry'];
$Reason=$_POST['Reason'];
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$phonenumber=$_POST['phonenumber'];
$emailid=$_POST['emailid'];
$message=$_POST['message']; 

$raw = $pool->get();
$raw->client->set_cql_version("3.0.0");

//$column_family->insert(array('industry' => '$Industry', 'Reason'=>'$Reason', 'firstname'=>'$firstname', 'lastname'=>'$lastname', 'phonenumber'=>'$phonenumber', 'emailadress'=>'$emailid', 'message'=>'$message'));

//$query = string 'INSERT INTO keshab.contact (industry, reason, first_name, last_name, phone, email, message) values ('$Industry', '$Reason', '$firstname', '$lastname', '$phonenumber', '$emailid', '$message')';

//$raw->client->execute_cql_query("INSERT INTO keshab.contact (industry, reason, first_name, last_name, phone, email, message) values ('$Industry', '$Reason', '$firstname', '$lastname', '$phonenumber', '$emailid', '$message')", 2);

$raw->client->execute_cql3_query("INSERT INTO keshab.contact (industry, reason, first_name, last_name, phone, email, message) values ('$Industry', '$Reason', '$firstname', '$lastname', '$phonenumber', '$emailid', '$message')", ConsistencyLevel::ONE);

}

$pool->close();



?>

I am getting error : Fatal error: Class 'ConsistencyLevel' not found in /var/www/phpcassandra/contact.php on line 42

Laap Saap

unread,
Dec 9, 2013, 8:31:53 AM12/9/13
to phpc...@googlegroups.com
You have to include the class. use cassandra\ConsistencyLevel;

keshab kumar

unread,
Dec 10, 2013, 1:17:34 AM12/10/13
to phpc...@googlegroups.com
Thank You Laap Saap for replying, now i have added the line and i ma getting new error now.This time error is

Fatal error: Uncaught exception 'cassandra\InvalidRequestException' in /var/www/phpcassandra/lib/cassandra/Cassandra.php:2031 Stack trace: #0 /var/www/phpcassandra/lib/cassandra/Cassandra.php(2031): thrift_protocol_read_binary(Object(Thrift\Protocol\TBinaryProtocolAccelerated), '\cassandra\Cass...', false) #1 /var/www/phpcassandra/lib/cassandra/Cassandra.php(2008): cassandra\CassandraClient->recv_execute_cql_query() #2 /var/www/phpcassandra/contact.php(46): cassandra\CassandraClient->execute_cql_query('INSERT INTO kes...', 1) #3 {main} thrown in /var/www/phpcassandra/lib/cassandra/Cassandra.php on line 2031





--
You received this message because you are subscribed to a topic in the Google Groups "phpcassa" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/phpcassa/p5ek_rfG9n4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to phpcassa+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Keshab Kumar,
PHP Developer,

Tyler Hobbs

unread,
Dec 10, 2013, 5:55:05 PM12/10/13
to phpc...@googlegroups.com
phpcassa doesn't support CQL, and what you have there is vulnerable to injection attacks.  Why not just use the normal phpcassa API?


--
You received this message because you are subscribed to the Google Groups "phpcassa" group.
To unsubscribe from this group and stop receiving emails from it, send an email to phpcassa+u...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.



--
Tyler Hobbs
DataStax

keshab kumar

unread,
Dec 11, 2013, 2:51:31 AM12/11/13
to phpc...@googlegroups.com
Hi Hobbs,

Is there any documentaion explaining how to use phpcassa API ?



--
You received this message because you are subscribed to a topic in the Google Groups "phpcassa" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/phpcassa/p5ek_rfG9n4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to phpcassa+u...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.



--

Tyler Hobbs

unread,
Dec 11, 2013, 12:59:11 PM12/11/13
to phpc...@googlegroups.com
The tutorial and API docs are here: http://thobbs.github.io/phpcassa/

There are some fully working examples here: https://github.com/thobbs/phpcassa/tree/master/examples

keshab kumar

unread,
Dec 17, 2013, 6:52:12 AM12/17/13
to phpc...@googlegroups.com

My doubt is if i am entering data in a table using " $column_family->insert('row_key', array()); " this function where key is uuid to maintain uniqueness.
Now i have a table for user registration having(username, email, password, gender, phone number, etc.). How to get the data for a specific user who is already  " $column_family->get('row_key', $column_slice=null, $column_names=$column_names); " in this function call we have to give the key which id uuid and i won't know each user key.
What is the correct may if getting data of my registered users?

Tyler Hobbs

unread,
Dec 20, 2013, 11:51:06 AM12/20/13
to phpc...@googlegroups.com
If you use UUIDs for row keys, they need to also be stored in a second place, like an index on email or username.
Reply all
Reply to author
Forward
0 new messages