Create and manipulate JSON data using PDOdb's JSON helpers.
use tommyknocker\pdodb\helpers\Db;
$db->find()->table('users')->insert([
'name' => 'Alice',
'meta' => Db::jsonObject([
'city' => 'NYC',
'age' => 30,
'verified' => true
])
]);$db->find()->table('users')->insert([
'name' => 'Alice',
'tags' => Db::jsonArray('php', 'mysql', 'docker')
]);$users = $db->find()
->from('users')
->select([
'id',
'name',
'city' => Db::jsonGet('meta', ['city'])
])
->get();$users = $db->find()
->from('users')
->where(Db::jsonPath('meta', ['age'], '>', 25))
->get();// Check if array contains value
$phpDevs = $db->find()
->from('users')
->where(Db::jsonContains('tags', 'php'))
->get();$users = $db->find()
->from('users')
->where(Db::jsonExists('meta', ['city']))
->get();$users = $db->find()
->from('users')
->select([
'id',
'tag_count' => Db::jsonLength('tags')
])
->get();$users = $db->find()
->from('users')
->select([
'id',
'meta_keys' => Db::jsonKeys('meta')
])
->get();$users = $db->find()
->from('users')
->select([
'id',
'tags_type' => Db::jsonType('tags')
])
->get();$db->find()->table('users')->insert([
'username' => 'alice',
'profile' => Db::jsonObject([
'bio' => 'Software Developer',
'location' => 'NYC',
'skills' => Db::jsonArray('PHP', 'MySQL', 'Docker')
])
]);$db->find()->table('products')->insert([
'name' => 'Laptop',
'specs' => Db::jsonObject([
'cpu' => 'Intel i7',
'ram' => '16GB',
'storage' => '512GB SSD',
'ports' => Db::jsonArray('USB-A', 'USB-C', 'HDMI')
])
]);- JSON Basics - JSON fundamentals
- JSON Querying - Query JSON
- JSON Filtering - Filter by JSON