[support] db_select()->condition()

Michael Prasuhn mike at mikeyp.net
Fri May 25 21:07:44 UTC 2012


No, no, no. SelectQuery::execute() does not return an array. 

Execute (at least for select queries) returns the result of DatabaseConnection::query which ends up returning the DatabaseStatement. To get an array of all results you'd have to call fetchAllAssoc() on the the resulting DatabaseStatement.

If you'd actually read the docs and the code you'd see that SelectQuery::execute and db_query() actually return the *exact same thing*. 

The real answer is that since both SelectQuery::execute and db_query end up calling and returning the same thing, is that the method for getting the query to execute with SelectQuery is much more convoluted, while helpful, each call to a method of SelectQuery, such as condition(), fields(), orderBy(), join(), etc takes additional time to execute, and then must be compiled into a string by calling __toString() on the query, the args have to be gathered by calling getArguments(), and so on.

Please look at the API docs and code before posting misinformation to the list.

-Mike
__________________
Michael Prasuhn
http://mikeyp.net

On May 25, 2012, at 1:16 PM, Earnie Boyd wrote:

> For others who are later looking at this thread, one consideration is
> that db_select()->execute() returns an array of rows of objects
> matching the select.  You could quickly consume all memory pulling all
> nodes so don't do something stupid like
> 
> $nodes = db_select('nodes', 'n')->fields('n')->execute();
> 
> To process one row at a time from the DB you must use db_query() which
> has an appropriate fetch() method to retrieve the data from the DB one
> row at a time.
> 
> Thanks for the responses David and Jamie, sounds like a heated debate
> but I now understand when db_select should be used and when not to.
> 
> -- 
> Earnie
> -- https://sites.google.com/site/earnieboyd
> -- 
> [ Drupal support list | http://lists.drupal.org/ ]



More information about the support mailing list