Orange-OpenSource / YACassandraPDO

Cassandra PDO Driver fork
Apache License 2.0
85 stars 32 forks source link

how to do batched write using YACassandraPDO? #84

Closed jayeshjain24 closed 9 years ago

jayeshjain24 commented 9 years ago

I wanted to insert multiple rows at once eg. https://lostechies.com/ryansvihla/2014/08/28/cassandra-batch-loading-without-the-batch-keyword/

Is it possible by using bindValue? or do I need to directly mention the parm in the query?

shobhit85 commented 9 years ago

It's possible using bindValue as long as your bind mappings are unique. What I mean by that is,

// Generate unique bind mappings in a loop $bind_mapping=array("row_1_column_1" => "bind_value_11", "row_1_column_12" => "bind_value_12", "row_2_column_1" => "bind_value_21", "row_2_column_2" => "bind_value_22");

Generate statements with unique bind 'keys' ("row_1_column_1")

$statement = "BEGIN BATCH "; $statement .= implode(" ", $statements); $statement .= " APPLY BATCH";

And then bind values in a loop again and then,

$result = $prepstmnt->execute();

This should work.