• For a long time, I’ve been using a function to filter user’s comments and add some information, like their roles and number of comments on my site. It’s working okay with PHP < 8, but after updating to any version >= 8, it returns a strange result. Is there any known bug/incompatibility of wpdb with version 8 of php?

    Example: inside my function, this is the result of $wpdb in PHP 7:

    wpdb Object
    (
    [show_errors] =>
    [suppress_errors] =>
    [last_error] =>
    [num_queries] => 145
    [num_rows] => 0
    [rows_affected] => 0
    [insert_id] => 0
    [last_query] => SELECT * FROM wp_users WHERE user_email = '[email protected]' LIMIT 1
    [last_result] => Array
    
    etc...

    So this way, I can get comment user’ ID and do my stuff, like this:

    $comm_count = $wpdb->get_var('SELECT COUNT (comment_ID) FROM ' . $wpdb->comments. ' WHERE comment_author_email = "' . get_comment_author_email() . '"');

    But with PHP 8, this is happening:

    wpdb Object
    (
        [show_errors] => 
        [suppress_errors] => 
        [last_error] => 
        [num_queries] => 132
        [num_rows] => 0
        [rows_affected] => 0
        [insert_id] => 0
        [last_query] => SELECT * FROM wp_users WHERE user_login = '#' LIMIT 1
        [last_result] => Array
    
    etc...

    The query goes from user_email to user_login, any clue why?

Viewing 1 replies (of 1 total)
  • How do you call $wpdb? What does your function in which you generated this debug output look like? And when is it executed?

Viewing 1 replies (of 1 total)
  • The topic ‘$wpdb bug with PHP > = 8?’ is closed to new replies.