tina4stack/tina4php-mongodb
Composer 安装命令:
composer require tina4stack/tina4php-mongodb
包简介
Tina4 PHP MongoDB Database Driver
README 文档
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
统计信息
- 总下载量: 42
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-12-08