1. Go to this page and download the library: Download greatcode/controller-global 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/ */
greatcode / controller-global example snippets
use Greatcode\ControllerGlobal\CtrlGlobal;
// From a Connection instance
$ctrl = new CtrlGlobal($connection);
// From a config array (passed to Connection::fromConfig)
$ctrl = new CtrlGlobal(['driver' => 'sqlite', 'dbname' => ':memory:']);
// With a custom AES encryption key
$ctrl = new CtrlGlobal($connection, 'my-secret-key');
// From environment variables / global $cfg array
$ctrl = new CtrlGlobal();
// Singleton
$ctrl = CtrlGlobal::getInstance();
$rows = $ctrl->GetGlobalFilter('SELECT * FROM users WHERE active = ?', [1]);
$rows = $ctrl->GetGlobalFilter(
'SELECT * FROM users WHERE role = :role',
[':role' => 'admin']
);
$rows = $ctrl->runSql('SELECT * FROM orders WHERE status = ?', ['pending']);
$name = $ctrl->getName('SELECT name FROM categories WHERE id = ?', [5]);
$conn = Connection::getInstance('mysql:host=127.0.0.1;dbname=mydb', 'user', 'pass');
// Subsequent calls with any arguments return the first instance
$same = Connection::getInstance();
$conn->transaction(function (Connection $db) {
$db->exec("INSERT INTO orders (total) VALUES (100)");
$db->exec("UPDATE stock SET qty = qty - 1 WHERE id = 5");
});
// Return values are passed through
$id = $conn->transaction(fn(Connection $db) => $db->lastInsertId());
use Greatcode\ControllerGlobal\CtrlGroupPos;
$pos = new CtrlGroupPos('PC-001', 'https://integrator.example.com');