This snippet shows you how to get a single query result as string in Drupal 7, using select from database abstraction layer.
Source code viewer
- $uid = reset(db_select('user', 'u')
- ->condition('u.username', $username)
- ->fields('u', array('uid'))
- ->range(0, 1)
- // Now that you have a single value, you can use it to load an entity for an example.
- $user = user_load($uid);Programming Language: PHP