public function __construct($options) { // Create me parent::__construct($options); // Set encoding $this->Query("SET NAMES '" . $this->encoding . "'"); }
public static function DB($connection = "") { // No connection given? if (empty($connection)) { // Get default connection $connection = ChickenWire::get("database::default"); // Null? if (is_null($connection)) { throw new Exception("No default database has been selected. Use ChickenWire::set('database::default').", 1); } } // Is the connection already made? if (array_key_exists($connection, self::$_databases)) { // Return it now return self::$_databases[$connection]; } // Look up settings $dbs = ChickenWire::get("database::connections"); if (is_null($dbs) || !array_key_exists($connection, $dbs)) { throw new Exception("No database connection found for '{$connection}'.", 1); } // Create $conn = Connection::Create($dbs[$connection]); // Store and return self::$_databases[$connection] = $conn; return $conn; }