admin管理员组文章数量:1321244
how to get results of a row with NULL element? I have to update the row which contains only the post_id and the repeat value, 'start' and 'end' should be NULL
mysql table screenshot: .png
$wpdb->update( $schedule_table, array( 'rpt' => $event_tag ), array( 'post_id' => $post_ID, 'start' => NULL, 'end' => NULL ), array( '%s' ) );
$wpdb->print_error();
I get this error:
WordPress database error: [] UPDATE wp_MW_3_schedule
SET rpt
= 'monday' WHERE post_id
= 357 AND start
= '' AND end
= ''
how to get results of a row with NULL element? I have to update the row which contains only the post_id and the repeat value, 'start' and 'end' should be NULL
mysql table screenshot: https://i.sstatic/r6pmA.png
$wpdb->update( $schedule_table, array( 'rpt' => $event_tag ), array( 'post_id' => $post_ID, 'start' => NULL, 'end' => NULL ), array( '%s' ) );
$wpdb->print_error();
I get this error:
WordPress database error: [] UPDATE wp_MW_3_schedule
SET rpt
= 'monday' WHERE post_id
= 357 AND start
= '' AND end
= ''
3 Answers
Reset to default 2My simple and quick solution is the use of a normal $wpdb->query() function:
$wpdb->query( $wpdb->prepare("UPDATE $schedule_table SET rpt = %s WHERE post_id = %d AND start IS NULL AND end IS NULL", $event_tag, $post_ID ) );
According to this ticket's comment, NULL
format is now working correctly and you can write your query as:
$wpdb->update(
$schedule_table,
array('rpt' => $event_tag),
array('post_id' => $post_ID, 'start' => NULL, 'end' => NULL),
array('%s'),
array('%d', NULL, NULL)
);
NULL is a php construct with special meaning, you should have probably used "NULL" instead.
$wpdb->update( $schedule_table, array( 'rpt' => $event_tag ), array( 'post_id' => $post_ID, 'start' => 'NULL', 'end' => 'NULL' ), array( '%s' ) );
本文标签: How to pass NULL in where array for wpdbgtupdate
版权声明:本文标题:How to pass NULL in where array for $wpdb->update 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742096846a2420602.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论