使用 quercus 在 php 中保存大字符串
我正在使用 quercus 作为 appengine。我尝试保存一个很长的 php 字符串(> 1000 个字符),但 appengine 不允许我保存,因为字符串只能容纳 500 个字符。所以我尝试使用appengine的文本数据类型。它可以让我保存,但是,当我从 PHP 检索数据时,它返回给我一个 resources() 类型而不是字符串。
让我用代码解释一下:
<?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 的内容时,它会返回一个 resources() 类型的数据。
<?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
}
?>
有什么解决方法吗?非常感谢任何帮助,因为我已经拉头发好几天了......
I'm using quercus for appengine. I tried saving a long php string (> 1000 characters) but appengine won't allow me as String can only hold 500 characters. So I tried using appengine's Text datatype. It lets me save, however, when I retrieve the data from PHP, it returns me a resource() type instead of string.
Let me explain with code:
<?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
?>
Now all's fine and dandy, but when I retrieve the content of $e, it will return me a resource() type data.
<?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
}
?>
Is there any workaround to this? Any help is GREATLY appreciated as I've been pulling my hair for days...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,通过将java对象转换为字符串解决了这个问题
Ok solved it by converting java object to string