I have a main site at www.mydomain.com. I have a wordpress blog set up at www.mydomain.com/blog. I want visitors to my main site to see the 3 recent blog posts. I was able to pull it off easily using the following code:
<?php
define('WP_USE_THEMES', false);
require('/home/mydomain/public_html/blog/wp-load.php');
query_posts('showposts=3');
?>
<?php while (have_posts()) : the_post(); ?>
<div class='category rounded_box'>
<?php if ( get_post_meta($post->ID, 'image', true) ) { ?>
<div class="category-thumbnail">
<a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><img src="<?php bloginfo('template_directory'); ?>/scripts/timthumb.php?src=<?php echo get_post_meta($post->ID, "image", $single = true); ?>&h=100&w=100&zc=1" width="100" height="100" border="0" /></a>
</div>
<?php } ?>
<div class='category_title'>
<h2><a href='<?php the_permalink() ?>'><?php the_title(); ?></a></h2>
</div>
<div class='duration_home'>
<?php the_excerpt(); ?>
<span>Posted on <?php the_time('F jS, Y') ?> - <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></span>
</div>
</div>
<?php endwhile;?>
<?php
wp_reset_query();
?>
Problem now is, anything on the page that requires calling a table for the main site no longer works. I’m getting an error saying it is searching for that table in the WordPress blogs database.
How do I break the connection to the WordPress database?
I know you fixed your issue, however, for future reference you should define each connection object when working with multiple connections. If your main database is on the same mysql server then you should be able to do a mysql_select_db($dbname); after you run the wordpress code; instead of closing and reopening the connection. For multiple connections follow the information from this answer: How do you connect to multiple MySQL databases on a single webpage?
The OP wrote in an edit: