Exemplo n.º 1
0
    /**
     * Shortcut to the Error::halt method.
     *
     * @param string $error DB error message
     */
    public function halt($error = 'Unknown error')
    {
        if (is_array($error) and isset($error[2]) and !empty($error[2])) {
            $error = $error[2];
        }
        else if (!is_array($error)) {
            $error = $error;
        }
        else {
            $error = 'Unknown error. ' . implode('/', $error);
        }

        Error::halt("Database Error", $error . '<br />' . $this->last_query);
    }
Exemplo n.º 2
0
Arquivo: pdo.php Projeto: nirix/avalon
    /**
     * PDO wrapper constructor.
     *
     * @param array $config Database config array
     */
    public function __construct($config, $name)
    {
        if (!is_array($config)) {
            Error::halt('PDO Error', 'Database config must be an array.');
        }

        // Lowercase the database type
        $config['type'] = strtolower($config['type']);

        try {
            $this->connection_name = $name;
            $this->prefix = isset($config['prefix']) ? $config['prefix'] : '';

            // Check if a DSN is already specified
            if (isset($config['dsn'])) {
                $dsn = $config['dsn'];
            }
            // SQLite
            elseif ($config['type'] == 'sqlite') {
                $dsn = strtolower("sqlite:" . $config['path']);
            }
            // Something else...
            else {
                $dsn = strtolower($config['type']) . ':dbname=' . $config['database'] . ';host=' . $config['host'];
                if (isset($config['port'])) {
                    $dsn = "{$dsn};port={$config['port']}";
                }
            }

            $this->connection = new \PDO(
                $dsn,
                isset($config['username']) ? $config['username'] : null,
                isset($config['password']) ? $config['password'] : null,
                isset($config['options']) ? $config['options'] : array()
            );

            unset($dsn);
        } catch (\PDOException $e) {
            $this->halt($e->getMessage());
        }
    }
Exemplo n.º 3
0
    /**
     * Determines the path of the view file.
     *
     * @param string $file File name.
     *
     * @return string
     */
    private static function _view_file_path($file)
    {
        $path = static::exists($file);

        // Check if the theme has this view
        if (!$path) {
            Error::halt("View Error", "Unable to load view '{$file}'", 'HALT');
        }

        unset($file);
        return $path;
    }