This problem occured for me when I included wp-blog-header.php from within a function (class method actually). This caused the global variables that WP sets to not be global for real, thus not being accessible by calling global $var. You get the error because $wpdb is global, but not really. I solved this by adding:
global $wpdb
Beneath the line: (in wp-settings.php on the line 269)
require_wp_db();
So the result looks like this:
require (ABSPATH . WPINC . '/compat.php');
require (ABSPATH . WPINC . '/functions.php');
require (ABSPATH . WPINC . '/classes.php');
require_wp_db();
global $wpdb; // Look look! Over here! line 270 in wp-settings.php
if ( !empty($wpdb->error) )
dead_db();
This however did not solve the problem. The same kind of error popped up elsewhere because of dependencies of other global variables in other places.
I just added the include(‘blog/wp-blog-header.php’); in my index.php outside of any functions (this is not the best solution for me because it means I have to include WP in all my page requests even when WP is not needed.)