• I’m working on integrating WP into an e-commerce site I built. The custom theme I’ve created does nothing except call the header and footer that we’re already using. So, header.php basically consists of two lines:

    require_once('/path/to/home/main.php');
    echo page_header();

    The main.php connects to another database running on the same server the WP installation is on, using PEAR’s DB.php connect function which is called statically:

    DB::connect($dsn, $options);

    (see DB::connect on pear.php.net)

    I’ve confirmed that once you connect to the database using DB::connect, the connection resource wpdb::$dbh gets set to this connection as well. This has produced bizarre problems since certain data in WP is queried before your theme header gets loaded and other data is queried afterwards. I don’t even know if this is a WP bug — it looks like it could be a conflict between PEAR’s DB.php and PHP’s native mysql_connect function.

    I’ve solved the problem by hacking the query function in /wp-includes/wp-db.php to force wpdb to call mysql_select_db every time, but this problem will reappear every time we have to upgrade.

    Has anyone run into a similar problem before? And is there a better solution than rewriting the wpdb class?

    Cheers,

  • The topic ‘Can’t use PEAR DB classes when inside WP themes’ is closed to new replies.