PHP code example of tina4stack / tina4php-mongodb

1. Go to this page and download the library: Download tina4stack/tina4php-mongodb library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tina4stack / tina4php-mongodb example snippets


global $DBA;

// Local MongoDB
$DBA = new \Tina4\DataMongoDb("localhost/27017:myDatabase");

// With authentication
$DBA = new \Tina4\DataMongoDb("localhost/27017:myDatabase", "username", "password");

class User extends \Tina4\ORM
{
    public $tableName = "users";
    public $id;
    public $name;
    public $email;
}

// Create
$user = new User();
$user->name = "Andre";
$user->email = "[email protected]";
$user->save();

// Read
$user = new User();
$user->load("name = 'Andre'");
echo $user->name;

// Update
$user->email = "[email protected]";
$user->save();

global $DBA;

// Insert
$DBA->exec("insert into users (name, email) values (?, ?)", "Andre", "[email protected]");

// Select
$result = $DBA->fetch("select name, email from users where name = 'Andre'");

// Update
$DBA->exec("update users set email = '[email protected]' where name = 'Andre'");

// Delete
$DBA->exec("delete from users where name = 'Andre'");