phpcassa library里有个namespace :
use phpcassa\Schema\DataType;
当使用cql query得到cqlrow, int32 & Date type会乱码:
string 'phpcassa\Schema\DataType\Int32Type' (length=34)
string '��09' (length=4)
string 'phpcassa\Schema\DataType\Int32Type' (length=34)
string '��09' (length=4)
string 'phpcassa\Schema\DataType\DateType' (length=33)
string '��:FA�' (length=8)
string 'phpcassa\Schema\DataType\UTF8Type' (length=33)
string '12345' (length=5)
这时,可以用DataType来unpack一下:
$rows = array();
foreach ($cql_result->rows as $rowIndex => $cqlRow) {
$cols = array();
foreach ($cqlRow->columns as $colIndex => $column) {
$type = DataType::get_type_for($cql_result->schema->value_types[$column->name]);
var_dump($type->__toString());
var_dump($column->value);
if($type->__toString() === "phpcassa\Schema\DataType\DateType"){
$cols[$column->name] = date("Y-m-d",$type->unpack($column->value,false));
}else{
$cols[$column->name] = $type->unpack($column->value,false);
}
}
$rows[] = $cols;
}
因为我有一个字段在cassandra里是timestamp类型,unpack出来的是time()的毫秒数,转换成date即可。