Using brian’s scripts a base and google’s jdo documentation, I’ve got a working example of reading from the app engine data store with php.

$q = $pm->newQuery("select from phptest.test");
$results = $q->execute();
//Returns a php array of resources. Foreach doesn't seem to work here. This seems to be an issue with Quercus.
$account = count($results);
for($a=0;$a < $account; $a++){
	echo $results[$a]->getId() . " - - " . $results[$a]->getFirstName() . '
'; } $pm->close(); ?>

Its just that easy.

Deletes work the same way too. The JDO persistence manager has a method called ‘deletePersistentAll()’ which will truncate the table. To delete a specific item, select it and call ‘deletePersistent(obj)’ where the obj is your record object. See the comments below.

JDO updates your data automatically. Select the item. Change the data and when you call the persistence managers close method, the changes will be saved.

Need more info: Read the google docs.

7 responses to “Quercus and App Engine – Reading from the data store.”

  1. Kali West Avatar

    I want to say, that I really love your blog.
    Please go on like that and don’t stop posting. I hope this comment motivates you to do so, smile
    regards, kali

  2. Herbert Groot Jebbink Avatar
    Herbert Groot Jebbink

    Hi, I’m have difficulties to implement the UD part of CRUD for this example. Below attemp to delete gives a 500 with java.lang.UnsupportedOperationException

    import phptest.test;
    import phptest.PMF;

    $p = PMF::get();
    $pm = $p->getPersistenceManager();
    $q = $pm->newQuery("select from phptest.test where id == 14");
    $results = $q->execute();

    echo $results[0]->getId() . " - " . $results[0]->getFirstName() . '';



  3. derak Avatar

    I see what you mean.

    As a workaround, you could call:


    The query only has one record loaded and that is the only record that will be deleted.
    This worked for me.

    Google has a 1000 record limit for queries so you’ll need to build that logic into your grid if your expecting more rows than that. See this link for more info on quotas and limits..

    For update, call the set method you defined in the java table class.

  4. Herbert Groot Jebbink Avatar
    Herbert Groot Jebbink

    Hi, I moved to the Quercus from Resin 4.0 and that solved a lot of problems, including the problem here described. However, your method is off course faster when deleting more records. (IMHO a interactive web-apps should never hit that 1000 record limit)

    I’m now working on a SQL to JDO wrapper. That way you can use ‘normal’ SQL statements in your PHP apps.

  5. Herbert Groot Jebbink Avatar

    Hi, see the URL below for an proof of concept how to use SQL CRUD (Create, Retrieve, Update, Delete) in PHP at Google App Engine.

  6. JaneRadriges Avatar

    The article is ver good. Write please more

  7. KattyBlackyard Avatar

    Hi, interest post. I’ll write you later about few questions!

Verified by MonsterInsights