tina4stack/tina4php-mongodb

Tina4 PHP MongoDB Database Driver

Maintainers

Package info

github.com/tina4stack/tina4php-mongodb

pkg:composer/tina4stack/tina4php-mongodb

Statistics

Installs: 42

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 0

v2.0.3 2026-03-14 19:36 UTC

This package is auto-updated.

Last update: 2026-03-14 19:36:34 UTC


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.

Tests

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

Code Infinity

Supporting open source communities Innovate Code Empower