How to get fetchField using db_query? I wrote db_query in two ways, I followed the drupal documentation to write safe db_query, one of them doesn't work, I want to know what I'm doing wrong in the code below.

// Worked perfectly
function custom_get_user_account_id() {
  global $user;
  return db_query("SELECT `field_account_target_id` FROM {field_data_field_account} where `entity_id`=:user_id and `bundle` = 'user'", array('user_id' =&gt; $user-&gt;uid))-&gt;fetchField();
}

// doesn't work
function custom_get_user_account_id() {
  global $user;
  return db_query("SELECT field_account_target_id FROM {field_data_field_account} fa where 'fa.entity_id = :user_id and fa.bundle = :user' ", array(':user_id' =&gt; $user-&gt;uid, ':user' =&gt; 'user'))-&gt;fetchField();
}
You could achieve this by either one of the following:

By using db_query():

function custom_get_user_account_id() {
    global $user;
    return db_query('SELECT field_account_target_id FROM {field_data_field_account} WHERE entity_id = :user_id AND bundle = :bundle', [
        ':user_id' =&gt; $user-&gt;uid,
        ':bundle' =&gt; 'user',
    ])-&gt;fetchField();
}


Or by using db_select():

function custom_get_user_account_id() {
    global $user;
    return db_select('field_data_field_account', 'fa')
        -&gt;fields('fa', ['field_account_target_id'])
        -&gt;condition('entity_id', $user-&gt;uid)
        -&gt;condition('bundle', 'user')
        -&gt;execute()-&gt;fetchField();
}