PHP code example of igorv / database

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

    

igorv / database example snippets




use IgorV\Database\DB;

DB::config([
    'dsn'      => 'mysql:host=localhost;dbname=example',
    'username' => 'username',
    'password' => 'password',
    'options'  => [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]
]);

$user = DB::table('users')->where('id', 1)->first();

$posts = DB::table('posts')->where('visible', true)->get();

$user = DB::table('users')->sortBy('created_at', 'desc')->as(User::class)->first();

$inserted = DB::table('users')->insert([
    'user'      => $user,
    'password'  => $password,
    'active'    => true
]);

$updated = DB::table('users')->where('id', $id)->update([
    'name'  => 'John Doe',
    'age'   => 41
]);

$deleted = DB::table('users')->where('age', '>', '10')->delete(); 

$number = DB::table('users')->where('active', true)->count();