0

I have a query like this:

  $product_classes = db_select('node_type', 't')->fields('t', array('name', 'type'))->condition('module','uc_product')
  ->execute()->fetchAllAssoc('orig_type', PDO::FETCH_ASSOC);

It will return an array with only first valid table row, however there are more valid rows.

If I use this query, without specified fields:

  $product_classes = db_select('node_type', 't')->fields('t')-:condition('module','uc_product')
  ->execute()->fetchAllAssoc('orig_type', PDO::FETCH_ASSOC);

It will return array with all the valid rows. It is a drupal bug?

1
  • 2
    No it's not a Drupal bug, but it could theoretically be a bug in a custom/contrib module, however unlikely that is. It's more likely you've got something wrong and haven't realised it, like the syntax error in your 2nd PHP statement, for example. Instead of executing the queries, cast them to a string and inspect the output. That will give you the actual SQL statements that will be run, which you can easily compare with one another, and try out directly against the db server to make sure the results are the same
    – Clive
    Mar 30 '16 at 11:41
0

The column name orig_type used in ->fetchAllAssoc('orig_type') must be included in

->fields('p', array('name', 'type', 'orig_type))

too, otherwise only one record will be returned.

0

Maybe the reason? "If the given key appears multiple times, later records will overwrite earlier ones." https://api.drupal.org/api/drupal/includes!database!database.inc/function/DatabaseStatementInterface%3A%3AfetchAllAssoc/7

1
  • The key is the same in both the cases, so it should returns the same value.
    – apaderno
    Mar 30 '16 at 21:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.