Filter results based on JSON path values and structure.
use tommyknocker\pdodb\helpers\Db;
// Find users with age > 25 in JSON
$users = $db->find()
->from('users')
->where(Db::jsonPath('meta', ['age'], '>', 25))
->get();$users = $db->find()
->from('users')
->where(Db::jsonPath('meta', ['age'], '>', 25))
->andWhere(Db::jsonPath('meta', ['age'], '<', 65))
->andWhere(Db::jsonPath('meta', ['verified']), true, '=')
->get();// Find users with 'php' in tags array
$phpDevs = $db->find()
->from('users')
->where(Db::jsonContains('tags', 'php'))
->get();// Find users with both 'php' AND 'mysql'
$fullStack = $db->find()
->from('users')
->where(Db::jsonContains('tags', ['php', 'mysql']))
->get();// Find users with 'city' in meta
$withCity = $db->find()
->from('users')
->where(Db::jsonPath('meta', ['city'], '!=', null))
->get();use tommyknocker\pdodb\helpers\Db;
$users = $db->find()
->from('users')
->where(Db::jsonExists('meta', ['city']))
->get();// Check nested JSON path
$users = $db->find()
->from('users')
->where(Db::jsonExists('profile', ['address', 'street']))
->get();$users = $db->find()
->from('users')
->select([
'id',
'name',
'meta_type' => Db::jsonType('meta')
])
->where(Db::jsonType('meta'), 'object', '=')
->get();// Search in deeply nested JSON
// meta: { profile: { address: { city: "NYC" } } }
$users = $db->find()
->from('users')
->where(Db::jsonPath('meta', ['profile', 'address', 'city'], '=', 'NYC'))
->get();// Find users with more than 5 skills
$users = $db->find()
->from('users')
->where(Db::jsonLength('skills'), 5, '>')
->get();// Find users who have all required skills
$users = $db->find()
->from('users')
->where(Db::jsonContains('skills', ['php', 'mysql', 'docker', 'redis']))
->get();$users = $db->find()
->from('users')
->where(Db::jsonPath('meta', ['age'], '>', 18))
->andWhere(Db::jsonPath('meta', ['age'], '<', 65))
->andWhere(Db::jsonContains('tags', 'php'))
->andWhere(Db::jsonExists('meta', ['city']))
->andWhere(Db::jsonLength('tags'), 3, '>')
->get();-- Virtual column + index
ALTER TABLE users
ADD COLUMN meta_age INT AS (JSON_EXTRACT(meta, '$.age'));
CREATE INDEX idx_meta_age ON users(meta_age);// Now query uses index
$users = $db->find()
->from('users')
->where(Db::jsonPath('meta', ['age']), 25, '>')
->get();// Store age in regular column for better performance
$db->find()->table('users')->insert([
'name' => 'Alice',
'age' => 30, // Regular column for fast queries
'meta' => Db::jsonObject(['detailed_info' => '...']) // JSON for flexible data
]);- JSON Querying - Extract JSON values
- JSON Modification - Update JSON
- JSON Basics - JSON fundamentals