Beispiel #1
0
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");
$db->pln($db->select("authors", ['fl' => $iArray, 'type' => 'num', 'where' => 'id=1']), "num");
$db->pln($db->select("books", ['where' => 'id<3']), "assoc");
$db->pln($db->select("books", ['where' => 'id<3', 'all' => 'all']), "all-assoc");