public static function getInstance($config) { self::$config = $config; $flag = $config['hostname'] . $config['database']; if (isset(self::$instances[$flag])) { return self::$instances[$flag]; } return self::$instances[$flag] = new self(); }
/** * Singleton constuctor * @param string $host The database servers address (IP or hostname), defaults to 'localhost' * @param string $database The MySQL database name. * @param string $user The MySQL database name. * @param string $pass The MySQL account password */ private function __construct($host, $database, $user, $pass) { try { self::$db = new PDO('mysql:host=' . $host . ';dbname=' . $database . '', $user, $pass); self::$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { echo "Connection Error: " . $e->getMessage(); } }
public function __construct($argv) { parent::__construct($argv); $this->checkDependencies(); $this->enforceCli(); if (!$this->isSuperUser()) { $this->writeln('You must be root to use this tool!'); $this->endWithError(); } $this->conf = $this->conductorConfiguration(); $this->mysql = MysqlPdo::connect('information_schema', $this->conf->mysql->username, $this->conf->mysql->password, $this->conf->mysql->host); }