PHP code example of ntentan / nzemba

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

    

ntentan / nzemba example snippets


namespace App\Models;

class User
{
    public ?int $id = null;
    public string $name;
    public string $email;
}

use App\Models\User;
use ntentan\nzemba\Repository;
use ntentan\nzemba\generators\Postgres;

$pdo = new PDO('pgsql:host=localhost;dbname=myapp', 'username', 'password');
$generator = new Postgres($pdo);

// Repository resolves table name to pluralized decamelized form (e.g., 'users')
$userRepository = new Repository(User::class, $generator);

// Insert a record
$userId = $userRepository->insert([
    'name' => 'Jane Doe',
    'email' => '[email protected]'
]);

$services = Repository::getService([
    'dsn' => 'pgsql:host=localhost;dbname=myapp',
    'user' => 'username',
    'password' => 'password'
]);