Problema de alcance variable. Mire global
function includehomepage() {
global $db;
$data = array();
$query = "SELECT pagecontent FROM `pages` WHERE `id` = '0'";
$query = mysqli_query($db, $query);
$data = mysqli_fetch_assoc($query);
return $data['pagecontent'];
}