How do I write a query using Drupal 7's query builder to return all the fields (SELECT *), not just the ones I specify through ->fields.
Edit: I tried something like
$query = db_select('table') ->condition('id', 2);
but when i echo it it's something like:
SELECT FROM {table} table WHERE (id = :db_condition_placeholder_0)
I haven't tested the query but my thoughts are the it will not work cause there is no * after SELECT.
This is how you do it:
<?php
$myId = 5;
$result = db_select('table', 't')
->fields('t')
->condition('id', $myId, '=')
->execute()
->fetchAssoc();
?>
the above is equivelent to:
SELECT t.* FROM table as t WHERE t.id = 7
More info is on the API documentation found here: https://api.drupal.org/api/drupal/includes!database!database.inc/function/db_select/7
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With