简体   繁体   中英

Missing argument 2 for wpdb::prepare(), called in /dbtable.php on line 252 and defined in /public_html/wp-includes/wp-db.php on line 1246

Everyday I see this error in log file:

PHP Warning: Missing argument 2 for wpdb::prepare(), called in /home/xxxxxxxx/public_html/wp-content/plugins/affiliate-link-cloaking/dbtable.php on line 252 and defined in /home/xxxxxx/public_html/wp-includes/wp-db.php on line 1246

In /dbtable.php on line 252 I have this code:

$result = $wpdb->query($wpdb->prepare("DELETE FROM ". $this->track_table_name . " WHERE YEAR(visittime)=". date('Y',$sdate) . " AND MONTH(visittime)=" . date('m',$sdate) ));

And in /wp-db.php on line 1246 I have this code:

public function prepare( $query, $args ) {

Please, keep in mind that I'm very inexperienced in PHP/SQL and I'll not understand general kind of tips. Please tell me, what to copy and paste where))

Thanks

That is not the correct way to use $wpdb->prepare , the first value should be the SQL with replacement tokens ( %s =string, %d =digit, etc), followed by the values to replace them with.

$sql = "DELETE FROM {$this->track_table_name} WHERE YEAR(visittime) = %d AND MONTH(visittime) = %d";
$query = $wpdb->prepare($sql, date('Y', $sdate), date('m', $sdate))
$wpdb->query($query);

See examples here:https://developer.wordpress.org/reference/classes/wpdb/prepare/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM