Support

Account

Home Forums Bug Reports MSSQL Escape Character Issue

Solved

MSSQL Escape Character Issue

  • Hi,

    I’ve recently set up a site using ACF on an IIS platform with MS SQL Server (using db abstraction plugin). We encountered an issue with field groups not being shown in the ACF screens or when editing posts/pages. I tracked the issue down to line 123 (v4.30) of core/controllers/field_group.php and the escape character used in the $wpdb->prepare statement.

    $rows = $wpdb->get_results( $wpdb->prepare("SELECT meta_key FROM $wpdb->postmeta WHERE post_id = %d AND meta_key LIKE %s", $post_id, 'field\_%'), ARRAY_A);

    Removing the backslash fixed the problem (and also didn’t cause any MySQL issues when I tested this on a LAMP stack since MySQL seems to ignore it when it becomes double escaped in the SQL query):

    $rows = $wpdb->get_results( $wpdb->prepare("SELECT meta_key FROM $wpdb->postmeta WHERE post_id = %d AND meta_key LIKE %s", $post_id, 'field_%'), ARRAY_A);

    Jonny

    • Elliot

    • November 14, 2013 at 4:03 pm

    Hi @jonnyvaughan

    Thanks for the bug report.
    I’ll add this to the to-do and find a solution which uses a WP function to do the like escape.

    I have a feeling that making this change to such a core function could effect some servers.

    I’ll let you know when I have some code to test!

    Thanks
    E

    • Elliot

    • November 21, 2013 at 10:52 am

    Hi @jonnyvaughan

    I’ve reviewed the code and have successfully removed the backslashes.
    Looking at the code, these backslashes don’t seem necessary, so I’ll push this to github and hope for no issues.

    Thanks
    E

  • Hi @elliot,

    Great – thanks for adding this fix.

    Jonny

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.