【问题标题】:Saving big string in php using quercus使用 quercus 在 php 中保存大字符串
【发布时间】:2010-09-29 17:55:39
【问题描述】:

我正在为 appengine 使用 quercus。我尝试保存一个长 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
}
?>

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

【问题讨论】:

    标签: php google-app-engine quercus


    【解决方案1】:

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

    $content = $i->getProperty('content');
    if(is_object($content)) {
        if($content instanceof Text) {
            $content = $content->getValue();
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-10
      • 1970-01-01
      • 2016-05-28
      • 2017-07-26
      • 2014-12-25
      • 2014-02-11
      相关资源
      最近更新 更多