[wp-trac] [WordPress Trac] #41997: Database error in SQL syntax ( $wpdb->prepare )
WordPress Trac
noreply at wordpress.org
Tue Sep 26 21:18:11 UTC 2017
#41997: Database error in SQL syntax ( $wpdb->prepare )
--------------------------+-----------------------------
Reporter: Track77 | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Database | Version: 4.8.2
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
I start receive next errors with new version.
This is an issue with function "$wpdb->prepare" on the line
{{{#!php
<?php
$query = preg_replace( '/%(?:%|$|([^dsF]))/', '%%\\1', $query );
}}}
Example code:
{{{#!php
<?php
global $wpdb;
$results = $wpdb->get_results(
$wpdb->prepare( '
SELECT %1$s.ID FROM %1$s WHERE %1$s.post_type = "post"
AND %1$s.post_status = "publish"
LIMIT 1
', $wpdb->posts ), ARRAY_N );
var_dump( $results );
}}}
Result:
{{{
WordPress database error You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right syntax
to use near '%1$s.ID FROM %1$s WHERE %1$s.post_type = "post"
AND %1$s.post_status = "pu' at line 1 for query
SELECT %1$s.ID FROM %1$s WHERE %1$s.post_type = "post"
AND %1$s.post_status = "publish"
LIMIT 1
made by require_once('.../wp-admin/admin.php'),
do_action('dashboard_page_test'), WP_Hook->do_action,
WP_Hook->apply_filters, test_online, include('.../test.php')
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/41997>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list