Title: External PHP include kills wp includes
Last modified: August 18, 2016

---

# External PHP include kills wp includes

 *  [Streetwise](https://wordpress.org/support/users/streetwise/)
 * (@streetwise)
 * [20 years, 4 months ago](https://wordpress.org/support/topic/external-php-include-kills-wp-includes/)
 * 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

Viewing 11 replies - 1 through 11 (of 11 total)

 *  Thread Starter [Streetwise](https://wordpress.org/support/users/streetwise/)
 * (@streetwise)
 * [20 years, 4 months ago](https://wordpress.org/support/topic/external-php-include-kills-wp-includes/#post-293308)
 * 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
 *  [whooami](https://wordpress.org/support/users/whooami/)
 * (@whooami)
 * [20 years, 4 months ago](https://wordpress.org/support/topic/external-php-include-kills-wp-includes/#post-293340)
 * 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.
 *  Thread Starter [Streetwise](https://wordpress.org/support/users/streetwise/)
 * (@streetwise)
 * [20 years, 4 months ago](https://wordpress.org/support/topic/external-php-include-kills-wp-includes/#post-293405)
 * 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
 *  Thread Starter [Streetwise](https://wordpress.org/support/users/streetwise/)
 * (@streetwise)
 * [20 years, 4 months ago](https://wordpress.org/support/topic/external-php-include-kills-wp-includes/#post-293406)
 *  Thread Starter [Streetwise](https://wordpress.org/support/users/streetwise/)
 * (@streetwise)
 * [20 years, 4 months ago](https://wordpress.org/support/topic/external-php-include-kills-wp-includes/#post-293407)
 * 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
 *  [whooami](https://wordpress.org/support/users/whooami/)
 * (@whooami)
 * [20 years, 4 months ago](https://wordpress.org/support/topic/external-php-include-kills-wp-includes/#post-293420)
 * $foobar is a variable 🙂 and yes, if the external script is checking another 
   db, you need to close that one.
 *  Thread Starter [Streetwise](https://wordpress.org/support/users/streetwise/)
 * (@streetwise)
 * [20 years, 4 months ago](https://wordpress.org/support/topic/external-php-include-kills-wp-includes/#post-293425)
 * 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.
 *  Thread Starter [Streetwise](https://wordpress.org/support/users/streetwise/)
 * (@streetwise)
 * [20 years, 4 months ago](https://wordpress.org/support/topic/external-php-include-kills-wp-includes/#post-293472)
 * anyone??
 * Thanks
 * Dave
 *  Thread Starter [Streetwise](https://wordpress.org/support/users/streetwise/)
 * (@streetwise)
 * [20 years, 4 months ago](https://wordpress.org/support/topic/external-php-include-kills-wp-includes/#post-293473)
 * 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.
 *  [whooami](https://wordpress.org/support/users/whooami/)
 * (@whooami)
 * [20 years, 4 months ago](https://wordpress.org/support/topic/external-php-include-kills-wp-includes/#post-293474)
 * 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.
 *  Thread Starter [Streetwise](https://wordpress.org/support/users/streetwise/)
 * (@streetwise)
 * [20 years, 4 months ago](https://wordpress.org/support/topic/external-php-include-kills-wp-includes/#post-293476)
 * Thanks for the help! Okay, so the site in question is [http://www.misionmeadows.org/2006/](http://www.misionmeadows.org/2006/)
 * My sidebar looks like this:
 * <div class=”sidebox”>
    <div class=”boxhead”>
    - <h3><?php _e(‘Camp Gallery’); ?></h3></div>
       <div class=”boxbody_random”>
 *  - <?php include(‘random.php’);?>
 * </div>
 * </div>
 * <div class=”sidebox”>
    <div class=”boxhead”>
    - <h3><?php _e(‘Want More?’); ?></h3></div>
       <div class=”boxbody”>
 *  - <?php wp_list_pages(‘title_li=’); ?>
 * </div>
 * </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/&#8217](http://www.missionmeadows.org/pix/&#8217););
   $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?

Viewing 11 replies - 1 through 11 (of 11 total)

The topic ‘External PHP include kills wp includes’ is closed to new replies.

## Tags

 * [external](https://wordpress.org/support/topic-tag/external/)
 * [php](https://wordpress.org/support/topic-tag/php/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 11 replies
 * 2 participants
 * Last reply from: [Streetwise](https://wordpress.org/support/users/streetwise/)
 * Last activity: [20 years, 4 months ago](https://wordpress.org/support/topic/external-php-include-kills-wp-includes/#post-293476)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
