SimpleQuery

I'm trying to user simplequery() but it seems I need to include something before. It gives me an error when a create the object ($query  = new SimpleQuery();)

Thank you!

  • SimpleQuery is not supported and has been removed from the 1.8 development version.

  • Thank you Cash

    It is still in 1.7 I'm using. Is there any fast alternative for 1.8? will query still be available?

    Thank you for your support

  • Query and its related classes have been removed from 1.8 because they were never fully implemented or supported.  A query class will be introduced in a later version of Elgg, but right now if you need to write manual SQL, use execute_query(), get_data(), or delete_data().

    Also, only rarely should plugin authors need to write manual SQL queries.  Can you do what you need to do using the existing API?

  • Thank you for your feedback. Yes I can do it with the existing API, but not efficencly.

    Before creating a new group I want to check another group with the same name already exists. It if does do something (not an error) and if it does then create it.

    I can query the guid of the groups and then query the name of each guid, it is fine, but with "zillions" of groups already created, and with "zillions" of requests for new groups it would overload the database. A simple SQL query could just check the name in the group table quickly, but I wanted to use the API instead, and simplequery() came handy.

    (ok, I know there is the question of why I need zillions of groups and requests, that's another problem :)

    Thank you!

  • As of 1.7 there is no way to get entities by name/title via the API, so you are correct to write your own SQL. We're looking into solutions for 1.8 that would allow sorting / retrieving entities by these attributes.

  • You should be able to do this through elgg_get_entities() by using a custom join and where clause.