• Hi,

    I have a separate database ‘XXX’ besides the wordpress db. I want to create a page to display data from this XXX db.

    I have created a page using a dedicated template xTest. When I run the page the error tells me it is trying to find wordpress tables in my XXX db.

    WordPress database error: [Table 'XXX.wp_posts' doesn't exist]
    SELECT * FROM wp_posts WHERE ID = 5 LIMIT 1

    Obviously XXX does not have a table called ‘wp_posts’

    Here is the code for my template file ‘xTest.php’ (incomplete)

    <?php
    /**
     * Template Name: xTest Template
     *
     * Description: for ..t.
     */
    ?>
    <?php get_header(); ?>
    
    <?php
    $host="localhost";
    $user="root";
    $password="xyz";
    $database="MySchool";
    
    $conn=mysql_connect($host,$user,$password);
    $ok=mysql_select_db($database,$conn);
    
    ?>
    		<div id="primary">
    			<div id="content" role="main">
    			</div><!-- #content -->
    		</div><!-- #primary -->
    
    <?php get_footer(); ?>

    I think mysql_select_db() is causing the error.

    Can anyone tell me what is wrong?
    Can anyone suggest a better way of displaying data from a second database? I have to use a separate db because existing programs are already using it.

    Thanks

  • The topic ‘How to display db data’ is closed to new replies.