示例#1
0
文件: eco_app.php 项目: r3-gis/EcoGIS
function R3AppInitDB()
{
    global $mdb2;
    global $dsn;
    require_once 'MDB2.php';
    if (!isset($dsn) || $dsn == '') {
        throw new Exception('Missing $dsn');
    }
    $txtDsn = $dsn['dbtype'] . '://' . $dsn['dbuser'] . ':' . $dsn['dbpass'] . '@' . $dsn['dbhost'] . '/' . $dsn['dbname'];
    $db = ezcDbFactory::create($txtDsn);
    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    PEAR::setErrorHandling(PEAR_ERROR_EXCEPTION);
    $mdb2 = MDB2::singleton($txtDsn);
    // Needed by user manager and import/export
    ezcDbInstance::set($db);
    if (isset($dsn['charset'])) {
        $db->exec("SET client_encoding TO '{$dsn['charset']}'");
        $mdb2->exec("SET client_encoding TO '{$dsn['charset']}'");
    }
    if (isset($dsn['search_path'])) {
        $db->exec("SET search_path TO {$dsn['search_path']}, public");
        $mdb2->exec("SET search_path TO {$dsn['search_path']}, public");
    }
    $db->exec("SET datestyle TO ISO");
    $mdb2->exec("SET datestyle TO ISO");
}
示例#2
0
 public function testChooseDefault()
 {
     $db = ezcDbInstance::get();
     $db = clone $db;
     $db->a = "something";
     ezcDbInstance::set($db, 'secondary');
     ezcDbInstance::chooseDefault('secondary');
     $this->assertEquals(true, isset(ezcDbInstance::get()->a));
 }
示例#3
0
<?php

require_once 'ezc/Base/base.php';
spl_autoload_register(array('ezcBase', 'autoload'));
ezcBase::addClassRepository('./lib', './lib/autoload');
$options = new ezcBaseAutoloadOptions();
$options->debug = true;
ezcBase::setOptions($options);
$rootdir = dirname(__FILE__);
$db = ezcDbFactory::create("sqlite://{$rootdir}/tmp/mergequeue.db");
ezcDbInstance::set($db);
示例#4
0
文件: runner.php 项目: naderman/pflow
 protected function handleDsn($value)
 {
     try {
         $ts = ezcTestSettings::getInstance();
         $settings = ezcDbFactory::parseDSN($value);
         $ts->db->value = $value;
         try {
             $ts->setDatabaseSettings($settings);
             $db = ezcDbFactory::create($settings);
             ezcDbInstance::set($db);
         } catch (ezcDbException $e) {
             die($e->getMessage());
         }
     } catch (Exception $e) {
         die("Database initialization error: {$e->getMessage()}\n");
     }
 }
示例#5
0
文件: Db.php 项目: heshuxian/mofang
 /**
  * Db constructor
  * @param array|string $dsn Connection DSN string or array of parameters
  * @return void
  */
 public function __construct($dsn = '')
 {
     $db = \ezcDbFactory::create($dsn);
     \ezcDbInstance::set($db);
 }
<?php

require_once __DIR__ . '/tutorial_example_01.php';
$pdo = new PDO('mysql:host=localhost;dbname=test', 'root', '');
// $db = new ezcDbHandlerMysql($pdo);
$db = ezcDbFactory::wrapper($pdo);
ezcDbInstance::set($db, 'wrapper');
ezcDbInstance::chooseDefault('wrapper');
$db = ezcDbInstance::get();
$res = $db->getAttribute(PDO::ATTR_DRIVER_NAME);
print_r($db);
print_r($res);
echo "\n----\n";
$pdo = new PDO('mysql:host=localhost;dbname=test', 'root', '');
// $db = new ezcDbHandlerMysql($pdo);
$db = ezcDbFactory::create($pdo);
ezcDbInstance::set($db, 'wrapper-1');
ezcDbInstance::chooseDefault('wrapper-1');
$db = ezcDbInstance::get();
$res = $db->getAttribute(PDO::ATTR_DRIVER_NAME);
print_r($db);
print_r($res);
示例#7
0
文件: config.php 项目: jeanvoye/utb
<?php

//ini_set( 'include_path', ini_get( 'include_path' ) . ':/htdocs/ezc_trunk/:.' );
ini_set('session.gc_maxlifetime', 864000);
require 'Base/src/ezc_bootstrap.php';
// ezcDbInstance::set( ezcDbFactory::create( 'sqlite://'. dirname( __FILE__ ) . '/share.sqlite' ) );
ezcDbInstance::set(ezcDbFactory::create('mysql://*****:*****@127.0.0.1/UnTrucBien'));
$options = new ezcBaseAutoloadOptions(array('debug' => true));
ezcBase::setOptions($options);
ezcBase::addClassRepository(dirname(__FILE__) . '/lib/share', null, 'share');
ezcBase::addClassRepository(dirname(__FILE__) . '/lib/debug', null, 'debug');
$log = ezcLog::getInstance();
$mapper = $log->getMapper();
$writer = new ezcLogUnixFileWriter("/tmp", "thewire-web.log");
$filter = new ezcLogFilter();
$rule = new ezcLogFilterRule($filter, $writer, true);
$mapper->appendRule($rule);
$reader = new ezcConfigurationIniReader();
$reader->init(dirname(__FILE__), 'settings');
$ini = $reader->load();
if ($ini->getBoolSetting('DevelopmentSettings', 'Debug')) {
    ezcBase::setRunMode(ezcBase::MODE_DEVELOPMENT);
    $debugHandler = ezcDebug::getInstance();
    $debugHandler->setOutputFormatter(new debugHtmlFormatter());
    debugLogger::setHandler($debugHandler);
}
$tc = ezcTemplateConfiguration::getInstance();
$tc->templatePath = dirname(__FILE__) . '/templates';
$tc->compilePath = dirname(__FILE__) . '/cache';
$tc->addExtension("shareTemplateFunctions");
示例#8
0
 /**
  * @internal
  */
 public function __construct($userSettings = null)
 {
     $configDir = '.';
     // Пользовательские настройки
     // --------------------------
     if (!is_array($userSettings)) {
         $userSettings = array('file' => $userSettings);
     }
     if ($file = @$userSettings['file']) {
         unset($userSettings['file']);
         if (file_exists($file)) {
             $configDir = dirname($file);
             $settings = Utils::loadConfig($file);
             Log::debug("Configuration load: " . realpath($file));
             unset($file);
             $userSettings = array_merge($userSettings, $settings);
         }
     }
     $userSettings = array_merge($this->defaultsSettings, $userSettings);
     if ($p = $userSettings['templates.path']) {
         if (substr($p, 0, 1) !== '/') {
             $userSettings['templates.path'] = SYSPATH . '/' . $p;
         }
     }
     // if (is_array($userSettings['import'])) {
     //     $import = $userSettings['import'];
     //     foreach ($import as $file) {
     //         $file     = $configDir . '/' . $file;
     //         $settings = Utils::loadConfig($file);
     //         if ($settings) {
     //             $defaultSettings = array_merge($defaultSettings, $settings);
     //             Log::debug("Configuration import",
     //                               array(realpath($file)));
     //         }
     //     }
     // }
     parent::__construct((array) $userSettings);
     $app =& $this;
     // Если Internet Explorer, то шлем на хуй
     /*
      if (preg_match('/(rv:11.0|MSIE)/i', $_SERVER['HTTP_USER_AGENT'])) {
      $app->log->warning('Bad Browser ', array('HTTP_USER_AGENT'=>$_SERVER['HTTP_USER_AGENT']));
      $app->redirect( "http://fobia.github.io/docs/badbrowser.html" );
      exit();
      }
     */
     // // Автоматическая загрузка секций конфигурации
     // ----------------------------------------------
     $autoload = $this['settings']['app.autoload'];
     if ($autoload) {
         $this['settings']['app'] = new \Pimple();
         $this['settings']['app']['autoload'] = $autoload;
         if (is_array($autoload)) {
             foreach (@$autoload as $cfg => $file) {
                 $this['settings']['app'][$cfg] = function ($c) use($cfg, $file, $configDir) {
                     Log::debug(">> autoload config", array($cfg, $file));
                     if (!file_exists($configDir . "/{$file}")) {
                         trigger_error("Нет автозагрузочной секции конфигурации '{$cfg}'" . "/{$file}", E_USER_ERROR);
                         return;
                     }
                     return Utils::loadConfig($file);
                 };
             }
         }
     }
     unset($autoload, $cfg, $file);
     // Session
     //  session.gc_maxlifetime = 1440
     //  ;setting session.gc_maxlifetime to 1440 (1440 seconds = 24 minutes):
     // ------------------
     $this['session'] = function ($c) {
         $sid = null;
         if ($c['settings']['session.cookie'] && @$_COOKIE['SID']) {
             $sid = $_COOKIE['SID'];
             session_id($sid);
         }
         $session = new \Slim\Session($c['settings']['session.handler']);
         @$session->start();
         if ($c['settings']['session.encrypt'] === true) {
             $session->decrypt($c['crypt']);
         }
         if ($sid === null) {
             $sid = session_id();
             if ($c['settings']['session.cookie']) {
                 @$c->setCookie('SID', $sid, time() + 1440);
                 Log::debug('Session save cookie');
             }
         }
         Log::debug('Session start', array($sid));
         return $session;
     };
     // View
     // ------------------
     $this['view'] = function ($c) {
         $view = $c['settings']['view'];
         if ($view instanceof \Slim\Interfaces\ViewInterface !== false) {
             return $view;
         }
         $view = new \Slim\Views\Smarty($c['settings']['templates.path']);
         $view->parserExtensions = SRC_DIR . '/src/Slim/Views/SmartyPlugins';
         $view->parserCompileDirectory = CACHE_DIR . '/templates';
         $view->parserCacheDirectory = CACHE_DIR;
         return $view;
     };
     // Database
     // ------------------
     $this['db'] = function ($c) {
         $db = \Fobia\DataBase\DbFactory::create($c['settings']['database']);
         \ezcDbInstance::set($db);
         return $db;
     };
     // Auth
     // ------------------
     $this['auth'] = function ($c) use($app) {
         $auth = new \Fobia\Auth\Authentication($app);
         $auth->authenticate();
         return $auth;
     };
     // API
     // ------------------
     // $this['apiHandler'] = function() {
     //     return new \Api\ApiHandler();
     // };
     // $this['api'] = $this->protect(function($method, $params = null) use ($app)  {
     //     $result = $app['apiHandler']->request($method, $params);
     //     return $result;
     // });
     // ------------------
     if (!self::$instance[0]) {
         self::setInstance($this);
     }
 }
示例#9
0
<?php

require 'ezc-setup.php';
$db1 = ezcDbFactory::create('mysql://root@localhost/ezc');
ezcDbInstance::set($db1, 'ezc');
$trunk = ezcDbFactory::create('mysql://root@localhost/trip');
ezcDbInstance::set($trunk, 'ezt');
$db = ezcDbInstance::get('ezt');
echo $db->getName();
示例#10
0
 public function __construct()
 {
     $db = ezcDbFactory::create('mysql://*****:*****@127.0.0.1/stats');
     ezcDbInstance::set($db);
 }