<?php

// DIC configuration
$container = $app->getContainer();
//use Lib\MVC4Slim\PdoLite;
use PdoLite\PdoLite;
use Lib\MVC4Slim\TwigExtension;
// Database
$container['pdolite'] = function ($c) {
    /*
    $settings = $c->get('settings')['pdolite'];
    $conn = PdoLite::dbConnect($settings['dsn'],$settings['username'],$settings['password']);
    */
    PdoLite::$cfg = $settings = $c->get('settings')['pdolite'];
    $conn = PdoLite::dbConnect($settings['dsn'], $settings['username'], $settings['password']);
    return $conn;
};
$container['pdo'] = function ($c) {
    $settings = $c->get('settings')['pdo'];
    print_r($settings);
    $conn = new PDO($settings['dsn'], $settings['username'], $settings['password']);
    echo "<br />Connect Info: ";
    print_r($conn);
    return $conn;
};
$container['capsule'] = function ($c) {
    $capsule = new Illuminate\Database\Capsule\Manager();
    $capsule->addConnection($c['settings']['db']);
    return $capsule;
};
// View
Exemple #2
0
<?php

include 'src\\pdolite.php';
use PdoLite\PdoLite;
if (file_exists("settings.php")) {
    include "settings.php";
} else {
    include "settings-dist.php";
}
PdoLite::$cfg = $cfg;
defined('PDOLITE_DB_DSN') or define('PDOLITE_DB_DSN', PdoLite::$cfg['dsn']);
defined('PDOLITE_DB_USER') or define('PDOLITE_DB_USER', PdoLite::$cfg['dbuser']);
defined('PDOLITE_DB_PASS') or define('PDOLITE_DB_PASS', PdoLite::$cfg['dbpass']);
$db = new PdoLite();
$db->dbConnect(PdoLite::$cfg['dsn'], PdoLite::$cfg['dbuser'], PdoLite::$cfg['dbpass']);
$iArray = ['idx' => 0, 'name' => 'some name', 'biography' => 'some bio', 'csrf_name' => 'csrf1280394586', 'csrf_value' => 'ccf28ee0ddd73'];
// SUDI: select, update, insert, delete test case
echo "<p />rows2array-bef";
$db->pln($db->select("authors"), "select-bef");
$sqlUpdList = ['biography' => 'Suzanne Marie Collins is an American television writer and novelist, best known as the author of The Underland Chronicles and The Hunger Games trilogy'];
$db->pln($db->update("authors", ['fl' => $sqlUpdList, 'where' => 'id=1']), "update");
$fldList = ['name' => "t'est", 'biography' => "t'est insert"];
$db->pln($db->insert("authors", ['fl' => $fldList]), "insert");
$lastid = $db->getLastId("authors", "id");
$db->pln($db->select("authors", ['where' => "id={$lastid}"]), "RS of last insert: {$lastid}");
$db->pln($db->delete("authors", ['where' => "id={$lastid}"]), "deleted {$lastid}");
$db->pln($db->select("authors"), "select-aft");
echo "<br />rows2array-after";
// various select test case
$db->pln($db->select("authors", ['fl' => 'name', 'type' => 'both', 'where' => 'id=1']), "both-name", 'p');
$db->pln($db->select("authors", ['fl' => 'id, name,xid', 'where' => 'id=1']), "name,xid");