OpenAds and Wordpress Plugin Conflict Solution

OpenAds and Wordpress Plugin Conflict SolutionIf you’ve come to this blog recently and found an error message in place of the content, I apologize for that. It was due to an incompatibility with OpenAds and the Popularity Contest plugin for wordpress. I shut off the plugin yesterday when I discovered what was going on and found the fix this morning. I thought I would share it with you all.

Basically this is what is going on (quoted from the forum post linked below)

Here’s the sequence of events that leads to the conflict:

  • Wordpress fires up, and uses mysql_query() to connect with the Wordpress database
  • At some point in your Wordpress theme, you”ll have pasted in the Openads PHP Local Invocation code to insert an ad. This creates a new connection to ANOTHER database (e.g. a database named “max”). By itself, this isn’t a bad thing.
  • However, Wordpress uses mysql_query again, with the apparent assumption that it’s still connected to the same database. Thus, it will try to do a query for a table in the Wordpress database while it is connected to the Openads database, and naturally will complain with a “WordPress database error” error message.

The error that I was getting looked like this:

the table jamese_openads.wp_ak_popularity_contest does not exist

As you can see it was indeed trying to use the open ads database I set up to access the wordpress plugin table.

The error message that you get only came up for me the first time I would view the homepage or any subsequent pages. I was slow about catching this one since it appeared that the problem would go away when I’d do a refresh, but Googleing “openads wordpress conflict” is what saved the day.

The solution is very easy. You can do one of 2 things:

  1. Don’t use the local invocation method for OpenAds. I want to use the local invocation method because I want my ads to be seen by everyone, not just people with Javascript turned on.
  2. Insert this code verbatim in after your invocation code:

    < ?php
    $wpdb->wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
    ?>

    So now your invocation code should look something like this:

    < ?php
    // The MAX_PATH below should point to the base of your Openads installation
    define(’MAX_PATH’, ‘/your/path/to/openads’);
    if (@include_once(MAX_PATH . ‘/www/delivery/alocal.php’)) {
    if (!isset($phpAds_context)) {
    $phpAds_context = array();
    }
    $phpAds_raw = view_local(”, 3, 0, 0, ”, ”, ‘0′, $phpAds_context);
    echo $phpAds_raw['html'];
    }
    ?>
    < ?php
    $wpdb->wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
    ?>

    That’s it.

Thanks to BobbyH for coming up with the fix which I found on the OpenAds Forum. The End

if you liked this post :)

Category: Programming | 1,731 views | Posted: September 6th 2007 06:52 am

Related Posts

Comments »

No comments yet.

Name (required)
E-mail (required - never shown publicly)
URI
Subscribe to comments via email
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> in your comment.

« PHP Application Framework Battle Royale: CodeIgniter vs. Symfony | Links from the Trenches #5 »