Forums

global $wpdb (3 posts)

  1. ronbowalker
    Member
    Posted 1 year ago #

    I am a newbe and I am trying to create a php file all on my own, and I would like to do a simple test to see that I have connected to my database correctly. And here is the code I am using to do the test...

    <?php
    global $wpdb;

    $query = $wpdb->get_results("Select post_title, ID, post_content, post_date, comment_count, iphone_image FROM wp_posts");

    blah-blah-blah.......
    echo....blah-blah-blah.
    ?>

    I get an error :
    Fatal error: Call to a member function get_results() on a non-object in /home/mysite/public_html/wp-includes/stuff/remote/tester.php on line 4

    I have done everything I can find in this forum, and I probably don't have it globalized properly...can someone tell me what to do?

    Thanks

  2. stvwlf
    Member
    Posted 1 year ago #

    Try using the $wpdb syntax for tablenames, like this

    $fivesdrafts = $wpdb->get_results("SELECT ID, post_title FROM $wpdb->posts
    	WHERE post_status = 'draft' AND post_author = 5");
  3. ronbowalker
    Member
    Posted 1 year ago #

    I did that just as you said....but no success.

    I appreciate the suggestion anyway. Thanks.

    Any other ideas are welcomed.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags