Custom post type hierarchical permalinks not behaving as expected for parent/child pages

I have solved the answer to this problem by doing this:

echo get_permalink( $page->ID );

This gave me the right links to the pages.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)