如何使用phpcassa在PHP中执行cassandra查询?

时间:2013-12-07 06:33:45

标签: php cassandra phpcassa

我正在尝试使用这个脚本在php中执行cassandra查询,但它会引发一个错误。任何人都可以帮我解决代码中的问题吗?

 <?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;


    $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();
    //$rawCon->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 = "insert into contact (industry, reason, first_name, last_name, phone, email, message) values ('$Industry', '$Reason', '$firstname', '$lastname', '$phonenumber', '$emailid', '$message')";

    $rows = $raw->client->execute_cql_query('$query');

    }

    $pool->close();



    ?>

这是我得到的警告: -

Warning: Missing argument 2 for cassandra\CassandraClient::execute_cql_query(), called in /var/www/phpcassandra/contact.php on line 40 and defined in /var/www/phpcassandra/lib/cassandra/Cassandra.php on line 2005 Notice: Undefined variable: compression in /var/www/phpcassandra/lib/cassandra/Cassandra.php on line 2007 

Fatal error: Uncaught exception 'Thrift\Exception\TApplicationException' with message 'Required field 'compression' was not present! 
Struct: execute_cql_query_args(query:24 71 75 65 72 79, compression:null)' 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(40): cassandra\CassandraClient->execute_cql_query('$query') 
#3 {main} thrown in /var/www/phpcassandra/lib/cassandra/Cassandra.php on line 2031

1 个答案:

答案 0 :(得分:0)

包括以下几行:

使用cassandra \ Compression;

$ rows = $ raw-&gt; client-&gt; execute_cql_query($ query,Compression :: NONE);