whereInt() / orWhereInt()
Type-safe WHERE condition for integer values.
Signature
whereInt(string $column, mixed $value, string $operator = '='): self
orWhereInt(string $column, mixed $value, string $operator = '='): self
Basic usage
Use whereInt() whenever you filter by an integer column like an ID,
a status flag, or a count. It ensures the value is a real integer before the
query is built.
// Step by step
$db->whereInt('id', 42);
$user = $db->getOne('users');
// Fluent
$user = $db->whereInt('id', 42)->getOne('users');
// → SELECT * FROM users WHERE id = 42 LIMIT 1
With operators
// Step by step
$db->whereInt('age', 18, '>=');
$db->whereInt('score', 100, '<=');
$rows = $db->get('users');
// Fluent
$rows = $db->whereInt('age', 18, '>=')
->whereInt('score', 100, '<=')
->get('users');
// → SELECT * FROM users WHERE age >= 18 AND score <= 100
Using orWhereInt()
// Step by step
$db->whereInt('type', 1);
$db->orWhereInt('type', 2);
$rows = $db->get('accounts');
// Fluent
$rows = $db->whereInt('type', 1)
->orWhereInt('type', 2)
->get('accounts');
// → SELECT * FROM accounts WHERE type = 1 OR type = 2
Validation & error handling
whereInt() accepts integers and numeric strings like '42'.
Anything else throws an InvalidArgumentException and resets the query state.
try {
$db->whereInt('id', 'abc'); // ❌ not a valid integer
$user = $db->getOne('users');
} catch (\InvalidArgumentException $e) {
echo $e->getMessage();
// → Invalid integer value for column 'id'.
}
Values that are rejected:
'abc'– not numeric'12.5'– float string, use whereFloat() instead'1; DROP TABLE users'– injection attemptnull– use whereIsNull() instead
See also
- whereIntIn() – filter by a list of integers
- whereFloat() – type-safe float filtering
- whereString() – type-safe string filtering
- whereTimestamp() – alias for whereInt() for Unix timestamps
- where() – generic WHERE without type enforcement