/**
  * Construct a new Database class instance
  * 
  * This takes a Data Source Name, or DSN, as its primary parameter. The format 
  * for this may be found on the 
  * {@link http://pear.php.net/manual/en/package.database.db.intro-dsn.php Pear DB documentation}
  * 
  * @param string $dsn The DSN for the required data source
  * @access private
  */
 private function __construct($dsn)
 {
     //Open a connection using the info in $dsn
     $this->conn = DB::connect($dsn);
     if (DB::isError($this->conn)) {
         //We're not connected.	Throw an exception
         throw new LoggedException($this->conn->getMessage() . " # " . $this->conn->getUserInfo(), $this->conn->getCode(), self::module);
     }
     //Always fetch data as an associative array
     $this->conn->setFetchMode(DB_FETCHMODE_ASSOC);
 }
Example #2
0
    }
    fclose($f_config);
    unset($arr);
    //
    $f = file_get_contents("../data/database.sql");
    $f = str_replace("%prefix%", Config::get("prefix"), $f);
    if (DB::createTB($f)) {
        exit("Successfully connected to the database. Refresh page.");
    }
} elseif (isset($_POST["link"])) {
    $link = $_POST["link"];
    unset($_POST["link"]);
    checkLink($link);
    //
    if (DB::existsLink($link)) {
        $code = DB::getCode($link);
    } else {
        while (true) {
            $time = time();
            $code = generate($time);
            if (!DB::existsCode($code)) {
                break;
            }
        }
        if (!DB::save($link, $code, $time)) {
            exit(Lang::get("ERR_SAVING_IN_DB"));
        }
    }
    exit($_SERVER['HTTP_HOST'] . "/" . $code);
} elseif (isset($_POST["c_link"])) {
    $link = $_POST["c_link"];