Im trying to integrate a WordPress blog into an existing website based on the Yii framework. I based my attempt on this article. My current website is located at the root of the domain and WP in a sub directory called "wp".
The WP site works. An integration test I made in a fresh php file works. But once I put the code into my Yii based code, I get the error "Error establishing a database connection".
Heres the code snippet I used in my Yii based code:
<?php spl_autoload_unregister(array('YiiBase', 'autoload')); define('WP_USE_THEMES', false); require('wp/wp-blog-header.php'); $posts = get_posts('numberposts=10&order=ASC&orderby=post_title'); foreach ($posts as $post) : start_wp(); ?> <?php the_date(); echo "<br />"; ?> <?php the_title(); ?> <?php the_excerpt(); ?> <?php endforeach; spl_autoload_register(array('YiiBase', 'autoload')); ?>
To avoid the WP and Yii autoloader from colliding, I added the calls to spl_autoload_unregister and spl_autoload_register. I've tried closing the Yii framworks DB connection before integrating WP, but with no luck.
My hope is that someone in this forum would have an idea as to how to solve this problem.