You are here

public static function BlockedIpsExpireTestCase::isIpInDatabase in Blocked IPs Expire 7

Returns TRUE if an IP address is in the database.

Parameters

string $ip: The IP address to check.

Return value

bool TRUE if the IP address to check is in the database, otherwise FALSE.

File

tests/blocked_ips_expire.base.test, line 29
Contains \BlockedIpsExpireTestCase.

Class

BlockedIpsExpireTestCase
An object containing test functions common to all tests for this module.

Code

public static function isIpInDatabase($ip) {
  $result = db_select('blocked_ips')
    ->condition('ip', $ip)
    ->countQuery()
    ->execute()
    ->fetchField();

  // If the number of results is greater than 0, then we can safely assume
  // that the IP address is in the database.
  return $result > 0;
}