WordPress.org

Support

Support » Plugins and Hacks » Can you perform an SQL query from this?

Can you perform an SQL query from this?

  • Great widget!

    But I need a way to perform a basic SQL query from your widget.

    This code here:
    1: <?php
    2: $querystr = “SELECT * FROM $wpdb->posts”;
    3:
    4: $pageposts = $wpdb->get_results($querystr, OBJECT);
    5: ?>

    produces this error here:

    “Fatal error: Call to a member function get_results() on a non-object in ..path../wp-content/plugins/execphp/execphp.php(24) : eval()’d code on line 4”

    how could i make an SQL query work from your widget?

Viewing 1 replies (of 1 total)
  • figured it out.

    you have to have global $wpdb; to access the db.

    so that’s:

    1: <?php
    2: global $wpdb;
    3: $querystr = “SELECT * FROM $wpdb->posts”;
    4: $pageposts = $wpdb->get_results($querystr, OBJECT);
    5: ?>

    works!

Viewing 1 replies (of 1 total)
  • The topic ‘Can you perform an SQL query from this?’ is closed to new replies.
Skip to toolbar