method connection documentation in bbn\Appui\Database

Returns a connection with the given user@host selecting the given database.

function(string $host = NULL, string $engine = 'mysql', string $db = '') { if (bbn\Str::isUid($host)) { $id_host = $host; } elseif (!($id_host = $this->hostId($host, $engine))) { throw new \Exception(X::_("Impossible to find the host").' '."$host ($engine)"); } if (!($cfg = $this->o->option($id_host))) { throw new \Exception(X::_("Impossible to find the option corresponding to host").' '."$host ($engine)"); } if ($id_host && ($parent = $this->o->parent($this->o->getIdParent($id_host)))) { if (!isset($this->connections[$parent['code']])) { throw new \Exception(X::_("Unknown engine")." ".$parent['code']); } if (!isset($this->connections[$parent['code']][$cfg['code'] . $db])) { switch ($parent['code']) { case 'mysql': if (strpos($cfg['code'], '@')) { $bits = bbn\X::split($cfg['code'], '@'); if (count($bits) === 2) { if (!($password = $this->getPassword($id_host))) { throw new \Exception(X::_("No password for %s", $cfg['code'])); } $db_cfg = [ 'engine' => 'mysql', 'user' => $bits[0], 'host' => $bits[1], 'db' => $db, 'pass' => $password ]; } else { $db_cfg = [ 'engine' => 'mysql', 'host' => $cfg['code'], 'db' => $db ]; } try { $this->connections[$parent['code']][$cfg['code'] . $db] = new bbn\Db($db_cfg); } catch (\Exception $e) { throw new \Exception($e->getMessage()); } } break; case 'postgre': if (empty($db) || empty($cfg['path'])) { throw new \Exception(X::_('db or path empty')); } break; case 'sqlite': if (empty($db) || empty($cfg['path']) || !file_exists($cfg['path'].'/'.$db)) { throw new \Exception(X::_('db or path empty')); } $db_cfg = [ 'engine' => 'sqlite', 'db' => $cfg['path'].'/'.$db ]; try { $this->connections[$parent['code']][$cfg['code'] . $db] = new bbn\Db($db_cfg); } catch (\Exception $e) { throw new \Exception($e->getMessage()); } break; default: throw new \Exception(X::_('Impossible to find the engine').' '.$cfg['engine']); } } if (isset($this->connections[$parent['code']][$cfg['code'] . $db])) { return $this->connections[$parent['code']][$cfg['code'] . $db]; } } throw new \Exception(X::_("Impossible to get a connection for").' '.$cfg['code']); }

Returns a connection with the given user@host selecting the given database. BBN is a suite of PHP and JS libraries and VueJS components - all open-source! bbn.io, build applications, the quick way

This website uses cookies to ensure you get the best experience on our website.