我在使用DataStax php驱动程序1.0.0-rc和Cassandra 2.2.3的Prepared Statements遇到奇怪的错误。我在这条线上有一个异常:
$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与标准选择查询结合使用,则可以使用。
有什么建议么?
您看到此错误是因为您只能将变量绑定到WHERE子句。准备好的语句机制不仅是美化的字符串格式化程序。它具有关于可以绑定和不能绑定的规则,以及在发送给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)
)));
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句