WordPress.org

Ready to get started?Download WordPress

Forums

Database Connection in WordPress (9 posts)

  1. thebindlestick
    Member
    Posted 7 years ago #

    I created a Page called editSubscriber, and then created a custom Template for this page so that I could run php/html code within the body. That works fine. The idea is to connect to my database (not my wordpress database but another database on the same server) and SELECT data from it, display it on the page and allow the user to edit the data. This is an internal intranet type page that will be passworded so don't freak out.

    Anyhow, when i try to connect to this other database from my Template page, it gives me an error that the table I am seeking does not exist. It is doing this because it is looking in the wordpress database and not the other one. My connection code specifically tells it which database to look in, but for some reason it keeps redirecting back to the wordpress database, dos anyone know how to avert this?

    When I run the script from the root wordpress directory it works fine. If I run it from my themes folder, it looks at the wrong database.

    My connection code:

    <?php
    // Makes initial conection to database
    define ('DB_USER', 'username');
    define ('DB_PASSWORD', '********');
    define ('DB_HOST', 'mysql15.myserver.com');
    define ('DB_NAME', 'cmsubsdata');
    
    $connect = @mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)
      	or die('Our database is currently down for updates, please check back later.'); 
    
    $db = @mysql_select_db(DB_NAME, $connect)
    	or die('Our database is currently down for updates, please check back later.');
    	?>
  2. whooami
    Member
    Posted 7 years ago #

    no-ones deleting it -- you're being tagged by askimet. it happens occasionally - relax. :)

  3. thebindlestick
    Member
    Posted 7 years ago #

    what does that mean?>

  4. whooami
    Member
    Posted 7 years ago #

    it means your posts disappear (for one thing),, until a mod fishes them out. Of course, if you repost they just have to pick through more ... It's not the end of the world, and it happens to a lot of people.

  5. thebindlestick
    Member
    Posted 7 years ago #

    fishes them out of where? Why do they disappear in the first place?

  6. whooami
    Member
    Posted 7 years ago #

    I'm not a forum mod, so I cant answer to that --

    All EYE know is that it happens, it can be triggered by posting too quickly, by posting too many links, etc.. it JUST fricken happens sometimes, it's software - its not perfect.

  7. thebindlestick
    Member
    Posted 7 years ago #

    what are the bbpress forums?

  8. whooami
    Member
    Posted 7 years ago #

    re: your original post. A wordPress created page will be calling the WordPress database first (and thats the important thing to realize). It's been discussed before. WordPress doesn't close the MySQL connection so it continuing to look in that db.

    There are more than a few posts here that discuss this - I found them searching for mysql_close() ...

    The simple way to fix this is to NOT create the page using WP. but there are other ways too.

    here's a good read, that will probably help:

    http://www.scriptygoddess.com/archives/2004/06/15/php-working-with-multiple-databases/

    Re: the askimet thing: Im not feeling chatty enough to continue.

  9. toomzee
    Member
    Posted 6 years ago #

    In reference to that scriptygoddess solution, where would i find the database connection code to alter it? What file is it in?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.