Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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: http://i.imgur.com/l27is.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

2 Answers 2

up vote 1 down vote accepted

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 ) );
share|improve this answer

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' ) );
share|improve this answer
    
No, it does not work either. –  Paul Geisler Dec 22 '12 at 9:41
    
interesting, do you know what is the actual query being sent? –  Mark Kaplun Dec 22 '12 at 10:17
    
It's: WordPress database error: [] UPDATE wp_MW_3_schedule SET rpt = 'monday' WHERE post_id = 357 AND start = 'NULL' AND end = 'NULL' –  Paul Geisler Dec 22 '12 at 10:19
    
maybe WordPress tries to sanitize and adds the "'" around NULL. If that is the case then your your use of query is probably the only way to do it –  Mark Kaplun Dec 22 '12 at 11:41
    
I guess so but thank you anyways for your support! Merry Christmas and Happy New Year! –  Paul Geisler Dec 23 '12 at 11:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.