The $db
object doesn't exist in the context of the function. You should pass it to the function as an additional parameter.
function GetCategory($db)
{
$sql = 'SELECT * FROM category ORDER BY order_cat DESC';
foreach ($db->query($sql) as $row)
{
echo "$row[name]
";
}
}
And read up on variable scope.