Location of core code for database connection and get_header

First off, the usual caveat — Don’t modify core code. (Certainly not on a production site.)

If you read the documentation on the Codex, you’ll notice that most if not all of the pages in, say, the Function Reference have a section called Source File. Clicking the link located there will take you to the file in trac where the particular function lives.

For instance, the Codex page for the_ID() points you to wp-includes/post-template.php.

Your specific questions:

Sometimes, though, you’ll have to hunt all over the WordPress codebase to follow the track of how does this work? You’ll find that functions call other functions, which call other functions, which apply filters, and so forth. There’s a lot of digging, sometimes, to understand how something in WordPress actually works. Do it. It’s worth it.