• I’m developing a plugin for my own site. In the admin area, I’m extending the WP_List_Table to display and maintain a table in my database. Things are working fine. In the prepare_items() function I create a SQL query based on the values I put in the search_box.

    The SQL searches work great.

    For debugging purposes, I capture the SQL query in a variable $sql and display the resulting SQL query on the admin screen below the list displaying the result of the query using this statement:

    <?php echo $sql ?>

    What is odd, is that LIKE queries display like this:

    SELECT * FROM table_download_log WHERE userName LIKE ‘{f30986d63aebf4bec8431c955043179b930581d76aacdf8324e0785ef22d4089}Jackson{f30986d63aebf4bec8431c955043179b930581d76aacdf8324e0785ef22d4089}’ ORDER BY downloadTime DESC LIMIT 50 OFFSET 0

    I know that the actual SQL query is:

    SELECT * FROM table_download_log WHERE userName LIKE ‘%Jackson%’ ORDER BY downloadTime DESC LIMIT 50 OFFSET 0

    How do I get the SQL query to display as is?

Viewing 2 replies - 1 through 2 (of 2 total)
  • You might want to use the error_log function instead of echo, so that it’s not affecting the layout of your screen.
    It could be that the SQL really does have that, at the point you captured it, because replacements are done internally using % wrapped variables, and the % in LIKE should not be changed. (this is a guess only) The prepare function might use a hash so that the % is not disturbed.

    Thread Starter amanandhishoe

    (@amanandhishoe)

    Thank you. I’ll try that. I know that the SQL doesn’t have that hash after the wpdb->prepare, because I saved the result in a field in the database, and when I look at that, it looks normal.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Problems displaying SQL query statements’ is closed to new replies.