model/c_db.php
/**
	 * Check if the query is accessing a collation considered safe on the current version of MySQL.
	 *
	 * @since 4.2.0
	 * @access protected
	 *
	 * @param string $query The query to check.
	 * @return bool True if the collation is safe, false if it isn't.
	 */
Check if the query is accessing a collation considered safe on the current version of MySQL.

@param string $query The query to check.
@return bool True if the collation is safe, false if it isn't.
Check if the query is accessing a collation considered safe on the current version of MySQL . @param string $query The query to check . @return bool True if the collation is safe false if it isn ' t .
protected function check_safe_collation( $query ) {
		if ( $this->checking_collation ) {
			return true;
		}
		$query = ltrim( $query, "\r\n\t (" );
		if ( preg_match( '/^(?:SHOW|DESCRIBE|DESC|EXPLAIN|CREATE)\s/i', $query ) ) {
			return true;
		}
		if ( $this->check_ascii( $query ) ) {
			return true;
		}
		$table = $this->get_table_from_query( $query );
		if ( ! $table ) {
			return false;
		}
		$this->checking_collation = true;
		$collation = $this->get_table_charset( $table );
		$this->checking_collation = false;
		if ( false === $collation || 'latin1' === $collation ) {
			return true;
		}
		$table = strtolower( $table );
		if ( empty( $this->col_meta[ $table ] ) ) {
			return false;
		}
		foreach ( $this->col_meta[ $table ] as $col ) {
			if ( empty( $col->Collation ) ) {
				continue;
			}
			if ( ! in_array( $col->Collation, array( 'utf8_general_ci', 'utf8_bin', 'utf8mb4_general_ci', 'utf8mb4_bin' ), true ) ) {
				return false;
			}
		}
		return true;
	}
protected function check_safe_collation ( $ query ) { if ( $ this -> checking_collation ) { return true ; } $ query = ltrim ( $ query , " \r \n \t  ( " ) ; if ( preg_match ( '/^(?:SHOW|DESCRIBE|DESC|EXPLAIN|CREATE)\s/i' , $ query ) ) { return true ; } if ( $ this -> check_ascii ( $ query ) ) { return true ; } $ table = $ this -> get_table_from_query ( $ query ) ; if ( ! $ table ) { return false ; } $ this -> checking_collation = true ; $ collation = $ this -> get_table_charset ( $ table ) ; $ this -> checking_collation = false ; if ( false === $ collation || 'latin1' === $ collation ) { return true ; } $ table = strtolower ( $ table ) ; if ( empty ( $ this -> col_meta [ $ table ] ) ) { return false ; } foreach ( $ this -> col_meta [ $ table ] as $ col ) { if ( empty ( $ col -> Collation ) ) { continue ; } if ( ! in_array ( $ col -> Collation , array ( 'utf8_general_ci' , 'utf8_bin' , 'utf8mb4_general_ci' , 'utf8mb4_bin' ) , true ) ) { return false ; } } return true ; }
Check if the query is accessing a collation considered safe on the current version of MySQL.
Check if the query is accessing a collation considered safe on the current version of MySQL .
// We don't need to check the collation for queries that don't read data. // All-ASCII queries don't need extra checking. // Tables with no collation, or latin1 only, don't need extra checking. // If any of the columns don't have one of these collations, it needs more sanity checking.