Opened 9 years ago
Closed 9 years ago
#41997 closed defect (bug) (duplicate)
Database error in SQL syntax ( $wpdb->prepare )
| Reported by: | Track77 | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Database | Version: | 4.8.2 |
| Severity: | normal | Keywords: | |
| Cc: | Focuses: |
Description
I start receive next errors with new version.
This is an issue with function "$wpdb->prepare" on the line
<?php $query = preg_replace( '/%(?:%|$|([^dsF]))/', '%%\\1', $query );
Example code:
<?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')
Change History (1)
Note:
See TracTickets
for help on using tickets.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Hi there, and thanks for the report.
The use of numbered variables is actually an unsupported syntax, as noted in the documentation, the introduction of numbered variables are being discussed in #41925.