PHP code example of mavi / dbmanager

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

    

mavi / dbmanager example snippets


->fetchSingle(); // Returns single value

$result = $dbManager->table('users')->select('id')->where(...)->fetchSingle(); // Returns 'id'
$result = $dbManager->table('users')->select('id, name, phone')->where(...)->fetchSingle(); // Returns 'id'
$result = $dbManager->table('users')->select('id, name, phone')->where(...)->fetchSingle(1); // Returns 'name'
$result = $dbManager->table('users')->select('id, name, phone')->where(...)->fetchSingle(2); // Returns 'phone'

->fetch(); // Returns single row as array
->fetchAll(); // Returns array of rows with values as associative array
->fetchPairs(); // Returns rows associated with unique key, values in a rows are associative array
    /*
     * fetchPairs example:
     * [
     *   2 => [id => 2, name => ... ]
     *   5 => [id => 5, name => ...]
     * ]
     */

$dbManager->beginTransaction();

try {
   $id = $dbManager->table('users')->insert(['name' => 'Karl', 'email' => '[email protected]'])->getId();
   $dbManager->table('orders')->insert(['user_id' => $id, 'price' => 1000, 'currency' => 'CZK', 'date%sql' => 'NOW()']);
   $dbManager->commit();

} catch (\Exception $e) {
   $dbManager->rollback();
}

$dbManager->table('users')->where('name LIKE ? AND birth_date = ?', 'Kar%', '1991-02-03')->update(['phone' => '+420 555 555 555']);