tina4stack / tina4php-mongodb
Tina4 PHP MongoDB Database Driver
v2.0.3
2026-03-14 19:36 UTC
Requires
- php: >=8.1
- ext-mongodb: *
- mongodb/mongodb: ^1.17
- tina4stack/tina4php-database: ^2.0
Requires (Dev)
- overtrue/phplint: ^2.0
- phpunit/phpunit: ^9
- roave/security-advisories: dev-latest
README
MongoDB database driver for the Tina4 PHP framework. Works seamlessly with the Tina4 ORM — write standard SQL and the built-in NoSQL parser translates it to native MongoDB operations.
Installing
composer require tina4stack/tina4php-mongodb
Requirements
- PHP >= 8.1
- MongoDB PHP extension (
ext-mongodb) - MongoDB PHP library (
mongodb/mongodb)
Usage
Basic Connection
global $DBA; // Local MongoDB $DBA = new \Tina4\DataMongoDb("localhost/27017:myDatabase"); // With authentication $DBA = new \Tina4\DataMongoDb("localhost/27017:myDatabase", "username", "password");
With Tina4 ORM
class User extends \Tina4\ORM { public $tableName = "users"; public $id; public $name; public $email; } // Create $user = new User(); $user->name = "Andre"; $user->email = "andre@example.com"; $user->save(); // Read $user = new User(); $user->load("name = 'Andre'"); echo $user->name; // Update $user->email = "new@example.com"; $user->save();
Direct Queries
global $DBA; // Insert $DBA->exec("insert into users (name, email) values (?, ?)", "Andre", "andre@example.com"); // Select $result = $DBA->fetch("select name, email from users where name = 'Andre'"); // Update $DBA->exec("update users set email = 'new@example.com' where name = 'Andre'"); // Delete $DBA->exec("delete from users where name = 'Andre'");
Docker (for testing)
docker run -d --name tina4_mongo -p 27017:27017 mongo
Running Tests
composer test
Our Sponsors
Sponsored with 🩵 by Code Infinity
Supporting open source communities • Innovate • Code • Empower