WordPress.org

Support

Support » Plugins and Hacks » get_row() with custom table and where statement returns null

get_row() with custom table and where statement returns null

  • In PHP I’ve used the following code in attempt to pull a single row to return the results in JSON format. If I remove my WHERE statement, the record returns fine (assuming I’m just testing with one record in the table.) If I add the WHERE statement back, it returns NULL. The exact same query, when pasted into phpmyadmin’s query tool, produces the desired record. Highly annoying, so if anyone could please point out what I’ve done wrong I would greatly appreciate it!

    For the sake of example, let’s assume I can confirm that “stringId1” (which is a varchar) does exist in the DB and I’ve culled the JSON output just to demonstrate the syntax I’m using.

    $queryString = "SELECT * FROM wp_sne WHERE id = 'stringId1'";
    $result = $wpdb->get_row($queryString);
    
    if ($result)
    	echo json_encode(array("id" => $result->id));

    POST Response: {“id”:null}

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘get_row() with custom table and where statement returns null’ is closed to new replies.