2

我正在将 quercus 用于 appengine。我尝试保存一个长 php 字符串(> 1000 个字符),但 appengine 不允许我,因为 String 只能容纳 500 个字符。所以我尝试使用 appengine 的 Text 数据类型。它可以让我保存,但是,当我从 PHP 检索数据时,它会返回一个 resource() 类型而不是字符串。

让我用代码解释一下:

<?php
$a = new Text("this is a long string that contains more than 1000 characters");
$b = "this is a long string that contains more than 1000 characters";
$e = new Entity('Article');
$e->setProperty('content', $a); // this works fine
// $e->setProperty('content', $b); // will complain as strlen($b) is > 500
$db = DatastoreServiceFactory::getDatastoreService();
$id = KeyFactory::keyToString($db->put($e)); // works ok, returns the ID of Entity saved
?>

现在一切都很好,但当我检索 $e 的内容时,它会返回一个 resource() 类型的数据。

<?php
$q = new Query('Article');
$ps = $db->prepare($q);
foreach($ps->asIterable() as $i) {
    echo gettype($i->getProperty('content')); // this will echo Object, which when var_dump'd, gives me a resource() which is not convertible to php string, thus I can't get the human readable value
}
?>

有什么解决方法吗?非常感谢任何帮助,因为我已经拉头发好几天了......

4

1 回答 1

0

好的通过将java对象转换为字符串来解决它

$content = $i->getProperty('content');
if(is_object($content)) {
    if($content instanceof Text) {
        $content = $content->getValue();
    }
}
于 2010-11-30T03:40:19.113 回答