Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cassandra使用datastax php驱动程序准备语句错误_Php_Cassandra_Prepared Statement_Datastax Php Driver - Fatal编程技术网

Cassandra使用datastax php驱动程序准备语句错误

Cassandra使用datastax php驱动程序准备语句错误,php,cassandra,prepared-statement,datastax-php-driver,Php,Cassandra,Prepared Statement,Datastax Php Driver,我在使用DataStax php驱动程序1.0.0-rc和Cassandra 2.2.3准备语句时遇到了奇怪的错误。我在这一行遇到了一个例外: $statement = $this->session->prepare("SELECT ? FROM ? WHERE ? = ?"); 我看到了这个错误: "error_code":33562624 "error_message":"Bind variables cannot be used for keyspace names" 下面

我在使用DataStax php驱动程序1.0.0-rc和Cassandra 2.2.3准备语句时遇到了奇怪的错误。我在这一行遇到了一个例外:

$statement = $this->session->prepare("SELECT ? FROM ? WHERE ? = ?");
我看到了这个错误:

"error_code":33562624
"error_message":"Bind variables cannot be used for keyspace names"
下面是用于与Cassandra通信的类存根:

class ClsCassandra extends ClsDbObject
{
    private $hostname="";
    private $username="";
    private $password="";
    private $keyspace="";
    private $poi_table="";
    private $poi_table_key_field="";
    private $poi_table_content_field="";

    private $cluster = NULL;
    private $session = NULL;

    private $threads = 1;

    function __construct()
    {
        ...
        ...
        //
        // i set up all the properties above
        //
        ...
        ...
    }

    public function runQuery(&$error)
    {
        try 
        {           
            $this->cluster   = Cassandra::cluster()
            ->withContactPoints($this->hostname)
            ->withCredentials($this->username, $this->password)
            ->withIOThreads($this->threads)
            ->build();

            $this->session = $this->cluster->connect($this->keyspace);

            // error on next line...
            $statement = $this->session->prepare("SELECT ? FROM ? WHERE ? = ?");
            $results = $this->session->execute($statement, new Cassandra\ExecutionOptions(array(
                    'arguments' => array($this->poi_table_content_field, $this->poi_table, $this->poi_table_key_field, $keypattern)
            )));

        }
        catch(Cassandra\Exception $ce)
        {
            $error->setError($ce->getCode(), $ce->getMessage(), $ce->getTraceAsString());
            $this->log(LOG_LEVEL, $error->getErrorMessage(), __FILE__, __LINE__, __CLASS__);
            return false;
        }
        return true;
    }

    ...
    ...
    ...
}
如果我将Simple Statemetn与标准的select查询一起使用,它就会工作


有什么建议吗?

您看到了这个错误,因为您只能将变量绑定到WHERE子句。prepared语句机制不仅仅是一个美化的字符串格式化程序。它有关于什么可以绑定和什么不能绑定的规则,以及在发送给Cassandra时如何绑定以消除任何歧义

您需要尝试以下方法:

$statement = $this->session->prepare(
    "SELECT key1, key2, col1, col2 FROM yourKeyspaceName.yourTableName WHERE key1 = ? AND key2 = ?");
$results = $this->session->execute($statement, new Cassandra\ExecutionOptions(array(
    'arguments' => array($key1,$key2)
    )));

亲爱的亚伦,非常感谢你的帮助。根据你的提示,我解决了这个问题。有没有网站可以让我看到准备好的报表申请的详细规则?Thx prevance.@omambe这里有一个指向Java驱动程序文档()的链接,该文档说明:“每次执行前使用准备好的语句并将新值绑定到列上。”准备好的语句背后的思想是提前构建CQL,并且每次查询只发送不同的列值(为了性能)。如果每次都要更改列、表或键空间名称,Cassandra如何保存查询以备将来使用?@omambe您可能还会发现这两篇博文很有帮助:和