whereBool()

The method whereBool() is a type-safe variant of where() used for filtering boolean-like fields such as TINYINT(1), BOOLEAN, or similar. It ensures the value is strictly interpreted as 0 or 1 and prevents logical injection or invalid values.

Method Signature

public function whereBool(string $column, bool|int $value, string $operator = '='): self

Basic Usage

Use this method to filter records based on boolean flags (e.g. is_active, deleted, published). The value will automatically be cast to 0 or 1 internally.

$db->whereBool('is_active', true);
$db->whereBool('deleted', 0);
$db->whereBool('published', 1, '!=');

$db->get('articles');

Allowed input and validation

The $value must be a valid boolean or integer (i.e. 0 or 1). Any other type or invalid number will be rejected.

Input Cast Accepted
true 1
false 0
1 1
0 0
'yes' ❌ rejected
2 ❌ rejected

Security Note

PDOdb performs type enforcement and security validation on all whereBool() calls. Unlike raw where(), it blocks invalid values and prevents logical injection (e.g. 1 OR 1=1).

Because all values are validated strictly and casted to 0 or 1, common injection patterns will not pass through this method.

Heuristic WHERE checks are applied if PDOdb_HEURISTIC_WHERE_CHECK is enabled. You can globally disable this layer via:
define('PDOdb_HEURISTIC_WHERE_CHECK', false);

Related Methods