Method to get a single instance of the database per connection
public static getInstance ( string $alias = 'standard', string $type = null, string $user = null, string $pass = null, array $option = null ) : object | ||
$alias | string | Pseudonym that will be used as a pointer to an instance of established connection |
$type | string | Connection type if using "Initial Setup" or "Full DSN" |
$user | string | Username of the database |
$pass | string | Password of the database |
$option | array | Configuration the connection driver |
return | object |
<?php // Loading all the necessary files require __DIR__ . '/src/bootstrap.php'; // Connection class imported use PDO4You\PDO4You; // Connection instance started and available PDO4You::getInstance(); // Applying styling on the page PDO4You::css(); // Displaying details on the target server's database connected PDO4You::showServerInfo(); ?> <!doctype html> <html> <head> <meta charset="UTF-8" /> <title>PDO4You</title> <style> body { background:#FAFAFA; font:normal 12px/1.7em Bitstream Vera Sans Mono,Courier New,Monospace; margin:0; padding:0; } a { color:#08C; text-decoration:none; } b { color:#CCC; } #pdo4you h2 { color:#000; background:#FFF; font-size:20px; display:block; margin:0; padding:10px; border-bottom:solid 1px #999; } .pagination { margin-top:25px;} .pagination a { color:#08C; background:#FFF; border:1px solid #BBB; font-size:12px; font-weight:bold; display:inline-block; min-width:13px; min-height:15px; margin:0 2px; padding:1px 6px; -webkit-border-radius:2px; -moz-border-radius:2px; border-radius:2px; text-align:center; cursor:pointer; } .pagination a.selected, .pagination a.selected:hover, .pagination a:hover { color:#FFF; background:#09E; border:1px solid #08C; } .pagination a.nolink, .pagination a.nolink:hover { color:#AAA; background:#FFF; border:1px solid #CCC; cursor:default; } </style> </head> <body id="pdo4you"> <?php if ((string) ($page = filter_input(INPUT_GET, 'p'))) {
<?php // Loading demo class require 'DemoCRUD.php'; // Example with Multiple Instances echo '<h2><a href=".">DEMOS</a> › MULTIPLE INSTANCES</h2>'; // Importing classes use PDO4You\PDO4You; // Creating an instance $demo = new DemoCRUD(); // Displaying records of the default instance "standard" $demo->select(); PDO4You::getInstance('bookstore', 'sqlite:data/database_bookstore.db'); PDO4You::getInstance('pdo4you', 'sqlite:data/database_pdo4you.db'); // Displaying records from the data instance: bookstore $demo->select('bookstore'); // Displaying records from the data instance: pdo4you $demo->select('pdo4you'); // Sets another instance PDO4You::setInstance('standard'); #PDO4You::setInstance('bookstore'); // Displaying records from the last data instance set $demo->select();
public function createDatabase() { // Connection instance started and available test::getInstance('test', 'sqlite::memory:'); }