Example #1
0
 /**
  * constructor
  **/
 public function __construct()
 {
     $this->host = db_host();
     $this->dbname = db_name();
     $this->user = db_user();
     $this->pass = db_psw();
     $this->path = db_path();
     switch (db_type()) {
         case "mysql":
             $dsn = 'mysql:host=' . $this->host . ";port=" . db_port() . ';dbname=' . $this->dbname;
             break;
         case "sqlite":
             $dsn = 'sqlite:' . $this->path . ';';
             break;
         case "postgresql":
             $dsn = 'pgsql:host=' . $this->host . ";port=" . db_port() . ';dbname=' . $this->dbname;
             break;
         default:
             $dsn = 'mysql:host=' . $this->host . ";port=" . db_port() . ';dbname=' . $this->dbname;
     }
     $connection = new PDOConnection($dsn, $this->user, $this->pass, [PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8', PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY, PDO::ATTR_TIMEOUT => 60 * 60 * 60 * 60, PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_PERSISTENT => false]);
     $connection->connect();
     $this->dbh = new Database($connection);
 }
/**
 * @internal
 * Check and get the database configuration settings
 * @param string $namespace Namespace of the configuration to read from
 */
function db_prerequisite($namespace = 'default')
{
    if (db_host($namespace) && db_user($namespace) && db_name($namespace)) {
        return db_config($namespace);
    } else {
        $error = new stdClass();
        $error->message = 'Required to configure <code class="inline">db</code> in "/inc/parameters/' . _cfg('env') . '.php".';
        $error->message = array(function_exists('_t') ? _t($error->message) : $error->message);
        $error->type = 'sitewide-message error';
        include _i('inc/tpl/site.error.php');
        exit;
    }
}
_autoloadDir(CLASSES . 'console');
_autoloadDir(LIB . 'commands');
_autoloadDir(APP_ROOT . 'commands');
_autoloadDir(APP_ROOT . 'cmd');
_autoloadDir(APP_ROOT . 'entity');
# DB configuration & DB helper (required)
if (isset($lc_databases[$lc_defaultDbSource]) && is_array($lc_databases[$lc_defaultDbSource]) && $lc_databases[$lc_defaultDbSource]['engine']) {
    if ($file = _i('helpers/db_helper.php', false)) {
        include $file;
    }
    $dbEngine = $lc_databases[$lc_defaultDbSource]['engine'];
    if ($dbEngine === 'mysql') {
        $dbEngine = 'mysqli';
    }
    require HELPER . 'db_helper.' . $dbEngine . '.php';
    if (db_host($lc_defaultDbSource) && db_user($lc_defaultDbSource) && db_name($lc_defaultDbSource)) {
        # Start DB connection
        db_connect($lc_defaultDbSource);
    }
}
_loader('session_helper', HELPER);
_loader('i18n_helper', HELPER);
_loader('validation_helper', HELPER);
_loader('auth_helper', HELPER);
_loader('pager_helper', HELPER);
_loader('form_helper', HELPER);
_loader('file_helper', HELPER);
if (file_exists(INC . 'autoload.php')) {
    require INC . 'autoload.php';
}
# Session helper (unloadable from /inc/autoload.php)