Home Forums Bug Reports MSSQL Escape Character Issue


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);


  • 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!


  • 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.


  • Hi @elliot,

    Great – thanks for adding this fix.


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

The topic ‘MSSQL Escape Character Issue’ is closed to new replies.