Use these helper functions for string operations across all databases.
Concatenate multiple strings:
use tommyknocker\pdodb\helpers\Db;
$users = $db->find()
->from('users')
->select(['full_name' => Db::concat('first_name', ' ', 'last_name')])
->get();
// SQL: CONCAT(first_name, ' ', last_name)$users = $db->find()
->from('users')
->select([
'email_with_name' => Db::concat('name', ' <', 'email', '>')
])
->get();Convert string to uppercase:
$users = $db->find()
->from('users')
->select(['name_upper' => Db::upper('name')])
->get();
// SQL: UPPER(name)Convert string to lowercase:
$users = $db->find()
->from('users')
->select(['email_lower' => Db::lower('email')])
->get();
// SQL: LOWER(email)Remove whitespace from both sides:
$users = $db->find()
->from('users')
->select(['name_trimmed' => Db::trim('name')])
->get();
// SQL: TRIM(name)Get string length:
$users = $db->find()
->from('users')
->select(['name_length' => Db::length('name')])
->get();
// SQL: LENGTH(name)Extract substring from string:
$users = $db->find()
->from('users')
->select(['first_char' => Db::substring('name', 1, 1)])
->get();
// SQL: SUBSTRING(name, 1, 1)$users = $db->find()
->from('users')
->select([
'email',
'domain' => Db::substring('email', Db::raw('LOCATE("@", email) + 1'))
])
->get();Replace text in string:
$users = $db->find()
->from('users')
->select(['clean_name' => Db::replace('name', 'Mr. ', '')])
->get();
// SQL: REPLACE(name, 'Mr. ', '')$users = $db->find()
->from('users')
->select([
'name',
'initials' => Db::concat(
Db::substring('first_name', 1, 1),
Db::substring('last_name', 1, 1)
)
])
->get();$addresses = $db->find()
->from('addresses')
->select([
'full_address' => Db::concat(
'street',
', ',
'city',
', ',
'state',
' ',
'zip'
)
])
->get();$users = $db->find()
->from('users')
->where(Db::lower('email'), Db::lower('test@example.com'), '=')
->get();
// SQL: WHERE LOWER(email) = LOWER('test@example.com')MySQL:
CONCAT(first_name, ' ', last_name)PostgreSQL/SQLite:
first_name || ' ' || last_namePDOdb handles this automatically.
// ✅ Clear
Db::concat('first_name', ' ', 'last_name')
// ❌ Less clear
Db::raw("first_name || ' ' || last_name")// For case-insensitive searches, create lowercase index
$db->connection->query('CREATE INDEX idx_users_email_lower ON users(LOWER(email))');
// Then use in queries
$users = $db->find()
->from('users')
->where(Db::lower('email'), Db::lower($email))
->get();- Numeric Helpers - Math operations
- Comparison Helpers - WHERE conditions
- Core Helpers - Essential helpers