How to convert a complex select query to Drupal dynamic query? I read online that db_query is faster than db_select for complex queries.
I wanted to check this for one of the queries I have written.

Following is the code with db_query:

$query = "SELECT og_users_roles.uid
        FROM {og_users_roles} AS og_users_roles
          LEFT JOIN {og_role} AS og_role
            ON og_users_roles.rid = og_role.rid
          LEFT JOIN {users} AS users
            ON og_users_roles.uid = users.uid
        WHERE og_users_roles.gid = :gid
          AND og_role.name =  :role_name
          AND users.uid &lt;&gt; 0
          AND users.status = 1";

$placeholders = array(
  ':gid' =&gt; $group_entity-&gt;nid,
  ':role_name' =&gt; OG_ADMINISTRATOR_ROLE,
);

$results = db_query($query, $placeholders)-&gt;fetchAll();


Now, before testing the performance I need to change above to user db_select.

This is what I have done:

$query = db_select('og_users_roles', 'o_u_r')
  -&gt;leftJoin('og_role', 'o_r', 'o_u_r.rid = o_r.rid')
  -&gt;leftJoin('user', 'u', 'o_u_r.uid = u.uid')
  -&gt;fields('o_u_r', array('uid'))
  -&gt;condition('o_u_r.gid', $group_entity-&gt;nid)
  -&gt;condition('o_r.name', OG_ADMINISTRATOR_ROLE)
  -&gt;condition('u.uid', 0, '&lt;&gt;')
  -&gt;condition('u.status', 1);

$results = $query-&gt;execute()-&gt;fetchAll();


However, this seems to fail with a WSOD.
Can someone point the error?
Give a try to Query coder module ( https://www.drupal.org/project/query_coder ): Convert SQL query to Drupal Database abstraction layer code.





Otherwise to debug the error turn on the error reporting, and check the error log which will point you to the suitable path.