This repository has been archived by the owner on Dec 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Links (Connections)
Kerem Güneş edited this page Jun 16, 2016
·
1 revision
Initializing
use Oppa\Database;
$db = new Database($cfg);
dump $db->connect()->getLink();
Simple connection for single database
// open connection
$db->connect();
// get connection
$db->getLink();
$db->getLink('localhost'); // assuming $cfg.database.host = localhost
// close connection
$db->disconnect();
$db->disconnect('localhost');
// null (after disconnect call)
$db->getLink();
$db->getLink('localhost');
Master/slave connection for multiple databases
// for master connection
$db->connect();
$db->connect('master');
$db->connect('master.mysql.local');
// for slaves connection
// - if empty, then connects to master
// - so must be indicated as "slaves" or "slave.host.XYZ"
$db->connect('slave'); // random
$db->connect('slave1.mysql.local');
$db->connect('slave2.mysql.local');
$db->connect('slave3.mysql.local');
$db->connect('slave3.mysql.local'); // no more try to connect for slave3, return exists
$db->connect('slave3.mysql.local'); // no more try to connect for slave3, return exists
$db->connect('slave3.mysql.local'); // no more try to connect for slave3, return exists
// get master connection
$db->getLink();
$db->getLink('master');
$db->getLink('master.mysql.local');
// get slave connection(s)
$db->getLink('slave'); // random
$db->getLink('slave1.mysql.local');
$db->getLink('slave2.mysql.local');
$db->getLink('slave3.mysql.local');
// close connection(s)
$db->disconnect('master');
$db->disconnect('slave');
// close all connections
$db->disconnect();
$db->disconnect('*');