我在使用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与标准选择查询,它可以工作 .
有什么建议?
1 回答
您看到此错误,因为您只能将变量绑定到WHERE子句 . 准备好的语句机制不仅仅是一个美化的字符串格式化程序 . 它有关于什么可以绑定和不绑定的规则,以及在发送到Cassandra时如何绑定事物以消除任何歧义 .
你需要尝试这样的事情: