PHP code example of patchlevel / rango

1. Go to this page and download the library: Download patchlevel/rango 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/ */

    

patchlevel / rango example snippets


use Patchlevel\Rango\Client;

// Connect to PostgreSQL using a standard PDO DSN
$client = new Client('pgsql:host=localhost;port=5432;dbname=app;user=postgres;password=postgres');

// Select database and collection (auto-created on first write)
$collection = $client->selectDatabase('test')->selectCollection('users');

// Insert a document (automatically generates an _id if missing)
$collection->insertOne([
    'name' => 'John Doe',
    'email' => '[email protected]',
    'tags' => ['php', 'postgres'],
    'metadata' => ['logins' => 0]
]);

// Find documents using MongoDB syntax
$users = $collection->find([
    'tags' => 'php',
    'metadata.logins' => ['$lt' => 10]
]);

foreach ($users as $user) {
    echo "Found: " . $user['name'] . " (" . $user['_id'] . ")\n";
}

// Atomic updates
$collection->updateOne(
    ['email' => '[email protected]'],
    ['$inc' => ['metadata.logins' => 1]]
);