Forums

Just started taking a peak at database class (2 posts)

  1. tanver
    Member
    Posted 2 years ago #

    Hi everybody, I have just started to take a peak at the WordPress database class, and have fallen into a problem, which I myself seems to be unable to resolve. Your help in this regard will highly be appreciated.

    Below please find the complete code of the test code I have written to get started with it. I have stored it under the root folder of a running WordPress instance.

    <?php
    global $wpdb;
    $myrows = $wpdb->get_results( "SELECT * FROM wp_posts" );
    ?>

    I know there must be some silly sort of error here .. may be something like $wpdb is out of the WordPress framework.

    The error returned is

    Fatal error: Call to a member function get_results() on a non-object in E:\xampp-w32\www\chadnicely\wyomingbuyhomes.com\testtool.php on line 4

    I will really appreciate a quick response on this.
    TIA

  2. MichaelH
    Volunteer
    Posted 2 years ago #

    If you are using this in a non-WordPress file, then look at:
    Integrating_WordPress_with_Your_Website

    Also this would be better:

    <?php
    global $wpdb;
    $myrows = $wpdb->get_results( "SELECT * FROM $wpdb->posts" );
    ?>

    Review wpdb

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags