The database layer in SugarCrm is designed in such a way that it is very agnostic, so you should never need to make calls to the actual database later functions, but rather use the exposed class methods for doing all the work needed. In listing bellow we making a query from the users table, iterating through the results, and making and updating the records if needed.

$db = DBManagerFactory::getInstance();
$res = $db->query("select * from users");
while ( $row = $db->fetchByAssoc($res) ) {
  // make some updates
  if ( $row['status'] != 'Active' ) {
      $db -> query("update users set is_admin = 0 where id = '{$row['id']}'");
  }
}