I am trying to write update query where id is not equal to 5
i want output like this but not working.
UPDATE `wp_messg` SET `is_read` = 1 WHERE `job_id` = 1 AND `biv_id`!=5
$id=5;
$wpdb->update(
'wp_messg',
array(
'is_read' => 1, // string
),
array( 'job_id' => $id,'biv_id' => $id ),
array(
'%d', // value1
),
array( '%d' )
);
}
I am trying to write update query where id is not equal to 5
i want output like this but not working.
UPDATE `wp_messg` SET `is_read` = 1 WHERE `job_id` = 1 AND `biv_id`!=5
$id=5;
$wpdb->update(
'wp_messg',
array(
'is_read' => 1, // string
),
array( 'job_id' => $id,'biv_id' => $id ),
array(
'%d', // value1
),
array( '%d' )
);
}
Share
Improve this question
asked Aug 20, 2016 at 16:45
user2477139user2477139
1014 bronze badges
2 Answers
Reset to default 1This is not something $wpdb->update()
method implements.
If you have custom SQL query that cannot be expressed in API you can run it as is with generic $wpdb->query()
.
It is not possible to use NOT EQUAL
in $wpdb->update()
. Here look the source code of the update
method-
public function update( $table, $data, $where, $format = null, $where_format = null ) {
if ( ! is_array( $data ) || ! is_array( $where ) ) {
return false;
}
$data = $this->process_fields( $table, $data, $format );
if ( false === $data ) {
return false;
}
$where = $this->process_fields( $table, $where, $where_format );
if ( false === $where ) {
return false;
}
$fields = $conditions = $values = array();
foreach ( $data as $field => $value ) {
if ( is_null( $value['value'] ) ) {
$fields[] = "`$field` = NULL";
continue;
}
$fields[] = "`$field` = " . $value['format'];
$values[] = $value['value'];
}
foreach ( $where as $field => $value ) {
if ( is_null( $value['value'] ) ) {
$conditions[] = "`$field` IS NULL";
continue;
}
$conditions[] = "`$field` = " . $value['format'];
$values[] = $value['value'];
}
$fields = implode( ', ', $fields );
$conditions = implode( ' AND ', $conditions );
$sql = "UPDATE `$table` SET $fields WHERE $conditions";
$this->check_current_query = false;
return $this->query( $this->prepare( $sql, $values ) );
}
NOT EQUAL
has not been handled. So it is not possible to use the NOT EQUAL
on $wpdb->update()
method.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744778041a4593162.html
评论列表(0条)