• I get an error when attempting to run the following PHP code:

    $mylink = $wpdb->get_row("SELECT * FROM teachers WHERE id = 10");
    
    echo $mylink->link_id;

    I get this error:
    Fatal error: Call to a member function get_row() on a non-object in (install_path)/wp-content/plugins/exec-php/includes/runtime.php(42) : eval()’d code on line 4

    I have tried this using two different PHP plugins, both give the same error. I have tried the query in the database and there are no errors with that.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter VonSeraph

    (@vonseraph)

    Sorry that second line of code should read:
    echo $mylink->id;

    My guess is that you need to declare

    global $wpdb;

    prior to your PHP code.

    Looks like you’re using the Exec-PHP plugin. Make sure you use
    caution in surfacing any PHP / database functionality. If the code makes use of visitor-supplied data (i.e. $_GET variables), then poorly-secured code can allow SQL injection and other exploits.

    If that’s all of the code that you have, it’s either as oxfordian said, or your DB query doesn’t return a record, so there’s no record to get the ID from. Either way you’ll get the same error message. It just depends which bit of the code is on line 4…

    Thread Starter VonSeraph

    (@vonseraph)

    Thanks for the reply. I am using the Insert PHP plugin.

    I added the line you suggested which gets rid of the error but doesn’t display anything. What am I missing now?

    It depends on whether there is a table named “teachers” with that specified row, etc. It depends on your particular data.

    If I were you, I’d temporarily include:

    print_r($mylink);

    after $mylink is set, to get more information on what was returned.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘MySQL Fatal error’ is closed to new replies.