Title: Include throws off WP
Last modified: August 18, 2016

---

# Include throws off WP

 *  Anonymous
 * [22 years, 1 month ago](https://wordpress.org/support/topic/include-throws-off-wp/)
 * Hi, I am really happy with WP. However, I am trying to change the template so
   that WP fits in with the site design.
    The site uses include files to display
   side menus and other items. The first file included is a function script which
   has database access details. When I add the includes, WP displays errors like
   so: [Table ‘dbase.wp_users’ doesn’t exist] SELECT * FROM wp_users WHERE ID = 
   3 [Table ‘dbase.wp_links’ doesn’t exist] [Table ‘dbase.wp_categories’ doesn’t
   exist] [Table ‘dbase.wp_posts’ doesn’t exist] WP is actually in dbase_4, not 
   dbase. It is getting the actual posts correctly from dbase_4, but my include 
   function file seems to be throwing WP, since the file has “dbase” as the database
   to connect to. I don’t get this, since the variables for database access are 
   different from WP’s: $dbhost = “myhost”; $dbuser = “dbase”; $dbpass = “mypass”;
   Any ideas on how I can fix this? Thanks.

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

 *  [Laughinglizard](https://wordpress.org/support/users/laughinglizard/)
 * (@laughinglizard)
 * [22 years, 1 month ago](https://wordpress.org/support/topic/include-throws-off-wp/#post-44139)
 * You can either move the WordPress includes to after your function script is done
   processing or you could re-include wp-config.php after you are done with the 
   function.
 *  Thread Starter Anonymous
 * [22 years, 1 month ago](https://wordpress.org/support/topic/include-throws-off-wp/#post-44145)
 * guess that makes sense, just got to figure out how to do it! 🙂
 *  Thread Starter Anonymous
 * [22 years, 1 month ago](https://wordpress.org/support/topic/include-throws-off-wp/#post-44147)
 * tried to re-include the wp_config.php file at the end of index.php but that did
   not work, same errors. Anyone else solved this problem or am I missing something?
 *  Thread Starter Anonymous
 * [22 years, 1 month ago](https://wordpress.org/support/topic/include-throws-off-wp/#post-44246)
 * Been working on this but still no luck….anyone else out there succeeded with 
   includes?
 *  [davidchait](https://wordpress.org/support/users/davidchait/)
 * (@davidchait)
 * [22 years, 1 month ago](https://wordpress.org/support/topic/include-throws-off-wp/#post-44248)
 * Ummm… I’ve got a dozen includes. It’s not includes generally, it is the specific
   thing you’re including.
    You want to post a link to a .phps-extensioned version
   of the file you are including? So we can take a look and tell you what’s going
   on… It must be overwriting some variables somewhere to get the result you’ve 
   noted. -d [http://www.chait.net](http://www.chait.net)
 *  Thread Starter Anonymous
 * [22 years, 1 month ago](https://wordpress.org/support/topic/include-throws-off-wp/#post-44285)
 * <?php
    function dbConnect($db=””) { $dbhost = “myhost”; $dbuser = “dbase”; $dbpass
   = “mypass”; $dbcnx = @mysql_connect($dbhost, $dbuser, $dbpass) or die(“The site
   database appears to be down.”); if ($db!=”” and !@mysql_select_db($db)) die(“
   The site database is unavailable.”); return $dbcnx; } ?> This is the script I
   include at the beginning of each page with db connection values. I thought the
   same as you, that the variables are getting overwritten somewhere, but I can’t
   see where, since these variables dont seem to be repeated by WP. I think its 
   this one that is throwing WP, since the error message I get: [Table ‘dbase.wp_users’
   doesn’t exist] SELECT * FROM wp_users WHERE ID = 3 suggests that it is trying
   to connect to “dbase.wp_users”. The actual db where WP resides is “dbase_4” in
   my case. Thanks for any help!
 *  [Ryan Boren](https://wordpress.org/support/users/ryan/)
 * (@ryan)
 * [22 years, 1 month ago](https://wordpress.org/support/topic/include-throws-off-wp/#post-44329)
 * wp-db.php uses those variables. Neither your variables nor wp-db’s are global,
   however, so there shouldn’t be a problem. I don’t have the code in front of me
   to be sure, though, so you might want to try renaming your variables just in 
   case.
 *  [davidchait](https://wordpress.org/support/users/davidchait/)
 * (@davidchait)
 * [22 years, 1 month ago](https://wordpress.org/support/topic/include-throws-off-wp/#post-44342)
 * yeah, so long as your variables aren’t declared global, and your dbConnect function
   isn’t overriding something else in WP, not sure why you’d get that error. it 
   SEEMS to be that you are somehow overriding the main database name…
    I’d start
   with just renaming your variables. Then the function. If that function is the
   only thing in the included file, and commenting out the include line mysteriously
   makes things work, there’s definitely some odd variable-overriding going on that
   shouldn’t be (from my knowledge of PHP…). -d
 *  Thread Starter Anonymous
 * [22 years, 1 month ago](https://wordpress.org/support/topic/include-throws-off-wp/#post-44362)
 * Still having trouble with my include file. I changed the variable names in the
   dbConnect function, did not work. Then I changed the function name from dbConnect
   to db_connect, did not work.
    I get the same error: [13-Apr-2004 10:12:04] PHP
   Warning: Invalid argument supplied for foreach() in wp-includes/template-functions.
   php on line 1514 Thats in my log files. On the WP index page, it says the usual:[
   Table ‘dbase.wp_users’ doesn’t exist] SELECT * FROM wp_users WHERE ID = 3 Stuff
   like that. I am sure a variable is getting overwritten, since the WP post itself
   shows up, but not the user name or the categories on the side. If I remove the
   includes from the WP index page, everything works fine……
 *  [davidchait](https://wordpress.org/support/users/davidchait/)
 * (@davidchait)
 * [22 years, 1 month ago](https://wordpress.org/support/topic/include-throws-off-wp/#post-44391)
 * Just to double check, you said “If I remove the includes”, PLURAL. Is that one
   function the only thing that needs to be removed to make things work? Are there
   multiple functions, multiple includes involved?
    With what you’ve posted, I can’t
   see why there’s a conflict. I’d assume there’s some other code somewhere that
   is messing with the same-named variables that the blog code uses. That’s my only
   thought at the moment. Again, if you duplicate the index file and all your custom
   included files (no need to do the wp includes, obviously…), and name them with
   a .phps extension (note the extra ‘s’ on the end) and have them up on your site—
   then post links to them here and we can poke around more specifically. Note that
   the ‘warning’ in your apache log may or may not be an ‘error’. There are many
   places in the wp code (and in mine too!) where the param passed to a foreach 
   loop isn’t checked for null/empty beforehand. -d [http://www.chait.net](http://www.chait.net)
 *  Thread Starter Anonymous
 * [22 years, 1 month ago](https://wordpress.org/support/topic/include-throws-off-wp/#post-44392)
 * Thanks David appreciate the help. Here is the link: [http://touringteam.com/wp/](http://touringteam.com/wp/)
   
   I changed only my database username/password for security in the db.phps file.
   The rest is as is…. Hope you see something I don’t! Jonathan
 *  Thread Starter Anonymous
 * [22 years, 1 month ago](https://wordpress.org/support/topic/include-throws-off-wp/#post-44417)
 * David, did you have a chance to look at this? I have had no luck as yet getting
   the variables to work. Thanks
 *  [davidchait](https://wordpress.org/support/users/davidchait/)
 * (@davidchait)
 * [22 years, 1 month ago](https://wordpress.org/support/topic/include-throws-off-wp/#post-44434)
 * 1. Make sure you have nothing after the “?>” in the php files. Looked to me like
   there was some extra garbage in at least one file, throwing things off, causing
   error msgs.
    2. just for sanity sake, you should either convert to using a new
   instance of the wpdb class to access your database, or store the returned ID 
   from db_connect and pass it into all your mysql_ function calls. To be EXTREMELY
   clear about which db you are accessing… 3. (matt or other wp devs, take note!)
   In wp-db.php, the line: $this->rows_affected = mysql_affected_rows(); should 
   be: $this->rows_affected = mysql_affected_rows($this->dbh); That’s a bug by my
   definition, don’t know that it’s an issue. Yet another reason for everything 
   to funnel through one well-debugged db management class (as the mysql fns can
   stomp all over each other if you don’t pass the db ID around…). 4. as I’ve said
   all along, it isn’t JUST a single include here. You have multiple cascaded includes,
   PLUS the menu.php file doing the db_connect call… It’s not just including a file
   that causes stuff to blow up generally. 😉 If the first 3 things didn’t help,
   try just commenting out the include of menu.php(s) and see if that does anything.
   Reading the code otherwise, wp-db.php looks to be using the db ID in all other
   calls, which should ensure that DB is being used when it is supposed to be. I
   don’t see any overriding of vars that should be causing the issue, so it has 
   to be something with the use of a secondary db — thus I think if all else fails,
   step 4 will resolve things. You can always import your custom tables into the
   wp db to alleviate the issue if we can’t otherwise resolve why this is happening.(
   I was trying to think of an issue where maybe there is/was a bug in certain releases
   of PHP and the mysql_ funcs, where the wrong DB is being accessed when multiple
   are open, regardless of the ID being passed in… that’s my only other thought…)-
   d [http://www.chait.net](http://www.chait.net)
 *  Thread Starter Anonymous
 * [22 years, 1 month ago](https://wordpress.org/support/topic/include-throws-off-wp/#post-44442)
 * Thanks David – I’ll give it a shot and report back!

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

The topic ‘Include throws off WP’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 14 replies
 * 4 participants
 * Last reply from: Anonymous
 * Last activity: [22 years, 1 month ago](https://wordpress.org/support/topic/include-throws-off-wp/#post-44442)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
