Help with a db_select() not returning results when it *should* I'm having trouble figuring out why the db_select() is not returning any results.  Long story short, if I pass the results of $results-&gt;execute() through a foreach ($results as $result), I don't get any results.  If I take the generated SQL and go directly to command line or phpMyAdmin (substituting manually for the placeholders) I get the expected result.  I feel like I have to just be overlooking something - I'm hoping fresh eyes can point it out for me.

Here is the select:



$results = db_select('product_charges_override', 'pc');
$results-&gt;join('products', 'p', 'p.product_id = pc.product_id');
$results-&gt;fields('pc', array('uid', 'product_id', 'override_count', 'redemption_count', 'coupon_code'))
  -&gt;fields('p', array('human_name'))
  -&gt;condition('pc.coupon_code', $coupon_code);
$results-&gt;execute();


Here is the result of dpq($results):

SELECT pc.uid AS uid, pc.product_id AS product_id, pc.override_count AS override_count, pc.redemption_count AS redemption_count, pc.coupon_code AS coupon_code, p.human_name AS human_name FROM {product_charges_override} pc INNER JOIN {products} p ON p.product_id = pc.product_id WHERE (pc.coupon_code = :db_condition_placeholder_0)


Here is the relevant Where statement from just var_dump($results):

protected 'where' =&gt; 
  object(DatabaseCondition)[136]
    protected 'conditions' =&gt; 
      array
        '#conjunction' =&gt; string 'AND' (length=3)
        0 =&gt; 
          array
            'field' =&gt; string 'pc.coupon_code' (length=14)
            'value' =&gt; string 'ugd2pl8z92j9' (length=12)
            'operator' =&gt; string '=' (length=1)
    protected 'arguments' =&gt; 
      array
        ':db_condition_placeholder_0' =&gt; string 'ugd2pl8z92j9' (length=12)
    protected 'changed' =&gt; boolean false
    protected 'queryPlaceholderIdentifier' =&gt; string '52e7fdf78bbd25.63959182' (length=23)
    public 'stringVersion' =&gt; string ' (pc.coupon_code = :db_condition_placeholder_0) ' (length=48)


And, finally, the query as I run it from the command line (notice the '{' and '}' have been removed, as well as the placeholder replaced with the value from the 'where' object). Those are the only things I replaced from the results of dpq().

SELECT pc.uid AS uid, pc.product_id AS product_id, pc.override_count AS override_count, pc.redemption_count AS redemption_count, p.human_name AS human_name FROM product_charges_override pc INNER JOIN products p ON p.product_id = pc.product_id WHERE (pc.coupon_code = 'ugd2pl8z92j9')


And an export from phpMyAdmin of the query results:

/**
 * Export to PHP Array plugin for PHPMyAdmin
 * @author Geoffray Warnants
 * @version 0.2b
 */

 //
 // Database "mats_theme"
 //

 // mats_theme.product_charges_override
 $product_charges_override = array(
       array('uid'=&gt;null,'product_id'=&gt;7,'override_count'=&gt;5,'redemption_count'=&gt;0,'human_name'=&gt;'Fleet Forum Registration')
);
I'm not assigning $results-&gt;execute() to anything - that's why I can't iterate over the results.  Answer was provided by a local mailing list that I sent this link to.

So, solution is $results = $results-&gt;execute().  Of course, the query should be renamed to something like, $query;