最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to pass NULL in where array for $wpdb->update

programmeradmin7浏览0评论

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 = ''

Share Improve this question asked Dec 20, 2012 at 12:50 Paul GeislerPaul Geisler 2901 gold badge3 silver badges11 bronze badges 0
Add a comment  | 

3 Answers 3

Reset to default 2

My 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' ) );
发布评论

评论列表(0)

  1. 暂无评论