I found the solution refering to this link
SQL Query
$role = $DB->get_records_sql("
select * from mdl_config where name='siteadmins'
");
$adminids = $role->value; // these are admin ids seperated by comma
I found the solution refering to this link