我在Hypertable中插入了数据。但我不知道,如何从结果中获得特定的价值。我的PHP thrift代码是:
$GLOBALS['THRIFT_ROOT'] = "/opt/hypertable/0.9.5.6/lib/php";
require_once $GLOBALS['THRIFT_ROOT'].'/ThriftClient.php';
$client = new Hypertable_ThriftClient("localhost", 38080);
$namespace = $client->namespace_open("appuniv");
$query = "select * from category_details limit 1";
$tab = $client->hql_query($namespace, $query);
var_dump($tab);
我得到以下结果:
object(Hypertable_ThriftGen_HqlResult)#24(4){[“results”] =>空值 [ “细胞”] => array(2){[0] =>对象(Hypertable_ThriftGen_Cell)#25(2) {[“key”] => object(Hypertable_ThriftGen_Key)#26(6){[“row”] => string(32)“077262cc53a1fb1b5f651d31b6bf81ba”[“column_family”] => string(8)“category”[“column_qualifier”] => string(4)“name” [ “时间戳”] => float(1.3419935154984E + 18)[“revision”] => float(1.3419935154984E + 18)[“flag”] => int(255)} [“value”] =>串(7) “医疗”} [1] => object(Hypertable_ThriftGen_Cell)#27(2){[“key”] => object(Hypertable_ThriftGen_Key)#28(6){[“row”] =>串(32) “077262cc53a1fb1b5f651d31b6bf81ba”[“column_family”] =>串(8) “category”[“column_qualifier”] => string(4)“type”[“timestamp”] => float(1.3419935154984E + 18)[“revision”] =>浮子(1.3419935154984E + 18) [ “标志”] => int(255)} [“value”] => string(7)“android”}} [ “扫描器”] => NULL [“mutator”] => NULL} 0.9678
我可以知道如何获得 [“value”] => string(7)来自上述结果的“医疗”值。
答案 0 :(得分:0)
/**
* Sort result by column family/qualifier
* @param thrift result
*/
private function sort($data)
{
$result = array();
foreach ($data as $cell)
{
$row = $cell->key->row;
if (!isset($result[$row])) {
$result[$row] = new stdClass;
$result[$row]->row = $cell->key->row;
foreach ($this->columns as $col) {
$pos = strpos($col, ':') ;
$qualifier = ($pos) ? substr($col, $pos + 1) : NULL;
$col = !$pos ? $col : substr($col, 0, $pos);
if (!$qualifier)
$result[$row]->{$col} = NULL;
else if ($qualifier[0] != '/')
$result[$row]->{$col}[$qualifier] = NULL;
}
}
$result[$row]->{$cell->key->column_family}[$cell->key->column_qualifier] = $cell->value;
}
return $result;
}