2
我用DataStax php驅動程序1.0.0-rc和Cassandra 2.2.3編寫的語句面臨奇怪的錯誤。我在這條線的異常:Cassandra用datastax php驅動程序編寫語句錯誤
$statement = $this->session->prepare("SELECT ? FROM ? WHERE ? = ?");
我看到這個錯誤:
"error_code":33562624
"error_message":"Bind variables cannot be used for keyspace names"
下面使用卡桑德拉到comunicate類的存根:
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;
}
...
...
...
}
如果我使用簡單Statemetn與標準的選擇查詢,而不是它的作品。
有什麼建議嗎?
親愛的亞倫,非常感謝您的幫助。按照你的提示我解決了。是否有網站,我可以看到詳細的規則申請準備好的聲明? Thx提前。 – omambe
@omambe這是一個指向Java驅動程序文檔的鏈接(http://docs.datastax.com/en/developer/java-driver/2.0/java-driver/quick_start/qsSimpleClientBoundStatements_t.html),其中指出:「使用預準備語句並在執行前每次將新值綁定到列。「準備好的語句背後的想法是,您正在提前構建CQL,並且只爲每個查詢發送不同的列值(用於性能)。如果您要每次更改列,表或鍵空間名稱,Cassandra如何保存查詢以供將來使用? – Aaron
@omambe您可能還會發現這兩篇博文很有用:http://www.datastax.com/dev/blog/4-simple-rules-when-using-the-datastax-drivers-for-cassandra和https:/ /ahappyknockoutmouse.wordpress.com/2014/11/12/246/ – Aaron