Database connections
-
Hi, I have a custom template which pulls data from a seperate source, not the wordpress database.
What is the best way to encapsulate / do the database connection so that there are no conflicts with wordpress?
<?php /* Template Name: High Run */ ?> <?php get_header(); ?> <div id="container"> <div id="content" role="main"> <?php if (have_posts()) while (have_posts()) : the_post(); ?> <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <h1 class="entry-title"><?php the_title(); ?></h1> <div class="entry-content"> <?php the_content(); ?> <?php // database connect mysql_connect($dbhost, $user, $password); mysql_select_db($database); $sql = "select * from $database.$table"; $results = mysql_query($sql); if ( mysql_num_rows($results) > 0 ) { print "<table><thead>"; print "<tr> <th>Name</th> <th>Province</th> <th>High Run</th> </tr> </thead> <tbody>"; while( $record = mysql_fetch_array($results)) { print "<tr>"; print "<td>" . $record['name'] . "</td>"; print "<td>" . $record['location'] . "</td>"; print "<td>" . $record['value'] . "</td>"; print "</tr>"; } print "</tbody></table>"; } // if mysql_num_rows } // end else ?> </div><!-- .entry-content --> </div><!-- #post-## --> <?php endwhile; ?> </div><!-- #content --> </div><!-- #container --> <?php get_footer(); ?>
- The topic ‘Database connections’ is closed to new replies.