Question

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...

Was it helpful?

Solution

Ok solved it by converting java object to string

$content = $i->getProperty('content');
if(is_object($content)) {
    if($content instanceof Text) {
        $content = $content->getValue();
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top