Merkucio
Merkucio

Reputation: 175

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

Upvotes: 1

Views: 357

Answers (1)

doublesharp
doublesharp

Reputation: 27599

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/

Upvotes: 1

Related Questions