• Can we please get some helpful error messages when wpdb just returns false, typiclly the process_fields function.

    i.e.

    
    /**
    	 * Processes arrays of field/value pairs and field formats.
    	 *
    	 * This is a helper method for wpdb's CRUD methods, which take field/value pairs
    	 * for inserts, updates, and where clauses. This method first pairs each value
    	 * with a format. Then it determines the charset of that field, using that
    	 * to determine if any invalid text would be stripped. If text is stripped,
    	 * then field processing is rejected and the query fails.
    	 *
    	 * @since 4.2.0
    	 *
    	 * @param string $table  Table name.
    	 * @param array  $data   Field/value pair.
    	 * @param mixed  $format Format for each field.
    	 * @return array|false An array of fields that contain paired value and formats.
    	 *                     False for invalid values.
    	 */
    	protected function process_fields( $table, $data, $format ) {
    		$data = $this->process_field_formats( $data, $format );
    		if ( false === $data ) {
    			$this->last_error = 'invalid formats';
    			return false;
    		}
    
    		$data = $this->process_field_charsets( $data, $table );
    		if ( false === $data ) {
    			$this->last_error = 'invalid charsets';
    			return false;
    		}
    
    		$data = $this->process_field_lengths( $data, $table );
    		if ( false === $data ) {
    			$this->last_error = 'invalid lengths';
    			return false;
    		}
    
    		$converted_data = $this->strip_invalid_text( $data );
    
    		if ( $data !== $converted_data ) {
    			$this->last_error = 'invalid data, affected fields: ';
    
    			foreach($data as $key => &$value)
    			{
    				if($value != ($converted_data[$key] ?? false))
    				{
    					$this->last_error .= $key;
    				}
    			}
    
    			return false;
    		}
    
    		return $data;
    	}
    
    • This topic was modified 3 years, 4 months ago by David Goring.

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Thread Starter David Goring

    (@dg12345)

    Also I should note that the DB errors are directly written to the error log

    Bypassing any error handling, why is this?

    I would like my rollbar plugin to be able to report db errors

Viewing 1 replies (of 1 total)
  • The topic ‘WPDB Error Messages’ is closed to new replies.