protected static function initDb() { global $copperDb; $user = copperConfig::get('dbUser'); $pass = copperConfig::get('dbPass'); $host = copperConfig::get('dbHost'); $name = copperConfig::get('dbName'); $dsn = "mysql:host={$host};dbname={$name}"; $copperDb = copperDb::configure($dsn, $user, $pass); self::set('copperDb', $copperDb); }
/** * configure * * Configure the instance * @param <type> $dsn * @param <type> $user * @param <type> $pass * @return db */ public static function configure($dsn, $user, $pass) { if (self::$instance !== NULL) { throw new Exception('copperDb already configured.'); } try { self::$instance = new copperDbPDO($dsn, $user, $pass); self::$instance->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); self::$instance->prepare("SET NAMES UTF8;")->execute(); } catch (Exception $e) { copperConfig::doError(" Configure: " . $e->getMessage() . " File: " . __FILE__ . ":" . __LINE__); echo "Hubo un error con la base de datos.\n"; die; } return self::$instance; }