WordPress.org

Ready to get started?Download WordPress

Forums

External PHP include kills wp includes (12 posts)

  1. Streetwise
    Member
    Posted 8 years ago #

    On my sidebar page, I wanted to include an external php page. So with the standard include, I got it to work, no problem.

    <?php include ("random.php"); ?>

    The problem though, is that it totally kills any remaining wp includes in the page. Seems as though the wp include tries to look at the DB tables from the external include and comes up with all sorts of "Table doesn't exist" errors.
    <?php wp_list_pages('title_li='); ?>

    I took a look at plugins such as RunPHP, and PHP_exec, but they really don't address what I'm experiencing, at least from what I can see. I tried searching but couldn't find anything like what's going on with my script.

    Thanks

    Dave

  2. Streetwise
    Member
    Posted 8 years ago #

    I may have found the reason for the problems:

    In the sidebar, there is a div class "boxbody" that is repeated for the various nav boxes. The first instance of boxbody contains the external PHP include:

    <div class="boxbody">

      <?php include ("random.php"); ?>
    </div>

    The second instance of boxbody, contains the wp include:

    <div class="boxbody">

      <?php wp_list_pages('title_li='); ?>
    </div>

    Maybe I that's where the first div class boxbody sees the external include and uses that for the remaining instances of boxbody?

    Could anyone verify that? Would I need to create a seperate div class?

    Thanks

    Dave

  3. whooami
    Member
    Posted 8 years ago #

    Is the external script making ANY database calls? If it is, make sure that it doesnt have a mysql_close($foobar) in it.

    If it does, it will close the connection causing any further queries to fail.

  4. Streetwise
    Member
    Posted 8 years ago #

    My theory (above) didn't pan out. I can put the external call outside of any div tags and the same thing happens -- WP-includes look to call data from their respective tables, but from within the database of the external include causing an error.

    The external include makes database calls to a database to display a random image. There is no type of mysql_close statement in it, or anything that comes close for that matter. Wouldn't it make more sense that it should include some type of database close statement since the wp-includes are trying to use the same table? I'm too new at this stuff to know. Maybe I'll try it.

    Thanks

  5. Streetwise
    Member
    Posted 8 years ago #


  6. Streetwise
    Member
    Posted 8 years ago #

    Closing in on this....

    I added mysql_close($foobar); to the random.php external include that I'm calling. Nothing happened.

    Next, I changed it to mysql_close();
    The random.php external include still works great, and now all of the error messages are gone! So what's happening now is that by adding that statement, All mysql connections closed after the external include executes. However, it effects all remaining database calls, including those that the wp-includes need (that's why there are no errors any more).

    So, was I supposed to substitute $foobar with something else? Perhaps the name of the database for the external include?

    Thanks

  7. whooami
    Member
    Posted 8 years ago #

    $foobar is a variable :) and yes, if the external script is checking another db, you need to close that one.

  8. Streetwise
    Member
    Posted 8 years ago #

    So if the name of the first db is 'gallery', you're saying that I should use something like mysql_close($gallery); in the php page that is being called?

    I tried it and it doesn't seem to work....

    I think I'm getting close to solving this thing....

    Thanks.

  9. Streetwise
    Member
    Posted 8 years ago #

    anyone??

    Thanks

    Dave

  10. Streetwise
    Member
    Posted 8 years ago #

    I might add that the external php includes work fine in the body, but not in the sidebar which is were they're needed... if that helps.

    Thanks.

  11. whooami
    Member
    Posted 8 years ago #

    oke, im back ..

    at the top of the external php script you are using there is something like this:

    $connect = mysql_connect($DB_SERVER, $DB_USER, $DB_PASS);

    in YOUR script, $connect is prolly called something else. THATS the variable you want to use with the mysql_close statement.

    So, in my own example, I would use:

    mysql_close($connect);

    follow? :)

    the position of the external script matters.. I do believe that wordpress closes its connections.. if you happened to place the script after ALL of the wp queries have been run AND the db were closed there would be no issue.

    Take a look, and try what I suggested.. :)

    On an aside, its very common to miss that a script might be making db calls that either need to be closed or NOT closed depending on what theyre accessing. I had a similar issue, with a script that WAS being closed but needed to remain open (it was using the same wordpress db) -- it closed the connection, and of course, all the subsequent queries failed. It just takes a little patience to figure things out.

  12. Streetwise
    Member
    Posted 8 years ago #

    Thanks for the help! Okay, so the site in question is http://www.misionmeadows.org/2006/

    My sidebar looks like this:

    <div class="sidebox">
    <div class="boxhead">

  13. <h3><?php _e('Camp Gallery'); ?></h3></div>
    <div class="boxbody_random">

      <?php include('random.php');?>

    </div>

  14. </div>

    <div class="sidebox">
    <div class="boxhead">

  15. <h3><?php _e('Want More?'); ?></h3></div>
    <div class="boxbody">

    • <?php wp_list_pages('title_li='); ?>

    </div>

  16. </div>

    You are correct in that if I put the external include at the bottom of the sidebar page, after all of the internal wp-includes, all is fine. It's only when I run it before any internal wp-includes is there an issue.

    As far as I can tell, this is the only thing I can find in the external random.php file that is the name of the database:

    include(ROOT_PATH.'config.php');
    include(ROOT_PATH.'includes/db_mysql.php');
    include(ROOT_PATH.'includes/constants.php');
    define('SCRIPT_URL', 'http://www.missionmeadows.org/pix/');
    $site_db = new Db($db_host, $db_user, $db_password, $db_name);

    So I tried adding mysql_close($site_db); to the end of the random.php file like this:

    echo "Comments: $image_comments<br>\n";
    mysql_close($site_db);
    ?>

    However, it doesn't seem to do anything. If I remove the $site_db from the string, the errors disappear, but so does the wp-includes...

    I'm wondering if there is another database name somewhere floating around?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags