db_affected_rows gives fatal error in drupal 7 How can i get the number of affected rows in drupal 7? db_affected_rows which i was used in d6 is not working in d7. It shows an error

 $bool = db_query("SELECT * FROM {template_config} WHERE user_role = ':d'",array(':d'=&gt; $id));
        $num = db_affected_rows();
        if ($num != 0) {
            $result = db_fetch_array($bool);
            $custom_theme = $result['theme_name'];
        }


i want to check if there is any affected rows.db_num_rows also is not working in d7
How can i do this in d7?
There is no db_affected_rows() in Drupal 7 I'm afraid. Also you don't need include the quotes in your variable placeholder. Your code might look a little more like this:

$results = db_query("SELECT * FROM {template_config} WHERE user_role = :role", array(':role' =&gt; 'the_role'))-&gt;fetchAll();

if (count($results) &gt; 0) {
  $first_result = $results[0];

  $custom_theme = $first_result-&gt;theme_name;
}


It could be even simpler though:

if ($result = db_query("SELECT * FROM {template_config} WHERE user_role = :role", array(':role' =&gt; 'the_role'))-&gt;fetchObject()) {
  $custom_theme = $result-&gt;theme_name;
}