WordPress.org

Ready to get started?Download WordPress

Forums

Can't Select Database when including wp-blog-header.php on seperate page (4 posts)

  1. carl_in_florida
    Member
    Posted 7 years ago #

    Hello

    The blog works fine. Has for years now.

    Trying to include the latest post on a separate index page of site.

    In the header I have

    <?php require("/home/path/to/wp/wp-blog-header.php"); ?>

    I am getting:

    WordPress

    Can’t select database

    We were able to connect to the database server (which means your username and password is okay) but not able to select the wp_wrdp1 database.

    * Are you sure it exists?
    * On some systems the name of your database is prefixed with your username, so it would be like username_wordpress. Could that be the problem?

    If you don't know how to setup a database you should contact your host. If all else fails you may find help at the WordPress Support Forums.

    Any ideas? I am hosted on my own box running Redhat. Again, wp works fine. I have about 5 wp installs on this box.

  2. underdog74
    Member
    Posted 7 years ago #

    The message that WordPress gives comes from the function select($db) in the wp-db.php file.

    It handles the standard mysql_select_db function. There is one advantage. They escape the error message that PHP / MySQL give by appending the @ in front of the function (at least, my version of WordPress does that)

    Advice is to:
    open
    wp-db.php
    find
    if (!@mysql_select_db($db, $this->dbh)) { (line 90)
    replace with
    if (!mysql_select_db($db, $this->dbh)) { (line 90)

    Hopefully mysql will give you a more precize error message. But you should really double check if the database wp_wrdp1 exists.

  3. carl_in_florida
    Member
    Posted 7 years ago #

    Thanks for the info underdog.

    It really exists. The blog works just fine. It has for years. I am just trying to access it from another page outside WP.

  4. carl_in_florida
    Member
    Posted 7 years ago #

    I was driving myself crazy with this so I did a work around.

    I created a file named latest.php and put it in the WP directory.

    I added this to it:

    <?php require('/home/pathtomy/wp-config.php'); ?>
     <?php
    $posts = get_posts('numberposts=1');
    foreach($posts as $post) :
    setup_postdata($post);
    ?>
    <a href="<?php the_permalink(); ?>"
    id="post-<?php the_ID(); ?>"><?php the_title(); ?></a>
    <?php the_content(); ?>
    <?php endforeach; ?>

    Then I simply did a php include on my front page

    <? php
    include'http://www.mydomain.com/blog/latest.php
    ?>

    And that is it!

    Hope this helps someone in the future!

Topic Closed

This topic has been closed to new replies.

About this Topic