PHP code example of parvezmrobin / db-model

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

    

parvezmrobin / db-model example snippets


$user = $users[0];
echo $user->name;
echo $user->email;
echo $users[2]->birth_day;

$user = \DbModel\Model::find('users', '1', 'user_primary_key');
$posts = $user->oneToMany('posts', 'user_id', 'user_primary_key');

// To retrieve Post that contains 'ghost' in title

$posts = $user->oneToMany('posts', 'user_id', 'user_primary_key',
    'title LIKE "%ghost%"');

// To retrieve title and body only
$posts = $user->oneToMany('posts', 'user_id', 'user_primary_key',
    'TRUE', 'title, body');

$post = \DbModel\Model::find('posts', '1');
$user = $post->manyToOne('user', 'user_id', 'user_primary_key');

// To specify the columns

$user = $post->manyToOne('user', 'user_id', 'user_primary_key', 'name, email');

$settings = \DbModel\Model::find('settings', '1');
$user = $post->manyToOne('user', 'user_id', 'user_primary_key');

$user = new Model();
$user->primary_key = 5;
$user->name = 'Christian Bale';
$user->updateById('users', 'primary_key');

$query = "SELECT * FROM table WHERE 1 = TRUE"
$result = (new \DbModel\Query('database_name'))->run($query);

foreach($result as $row) {
    foreach($row as $key => $value) {
        echo $key, ': ', $value;
    }
    echo '<br>';
}