Ejemplo n.º 1
0
 /**
  * 构造方法
  * @param string $dbsource
  */
 public function __construct($dbsource = null)
 {
     // 模型初始化
     $this->_initialize();
     if (is_null($dbsource)) {
         $this->db = Factory::db($this->setting);
     } else {
         $this->db = Factory::db($dbsource);
     }
     $this->database = $this->db->get_database();
     // 获取数据库名
     $this->prefix = $this->db->get_prefix();
     // 获取表前缀
     $this->table_name = $this->prefix . $this->table_name;
     // 字段检查
     if ($this->auto_check_fields && $this->table_name != $this->prefix) {
         $this->_check_table_info();
     }
 }
Ejemplo n.º 2
0
 * CHARACTER SET
 ************************************************************************/
ini_set('default_charset', 'UTF-8');
if (extension_loaded('mbstring')) {
    mb_internal_encoding(CHARSET);
}
/************************************************************************
 * CONNECT TO DATABASE(S)
 ************************************************************************/
if (defined('DB_NAME')) {
    $db =& Factory::db(array('dsn' => DB_DSN, 'file' => DB_FILE, 'host' => DB_HOST, 'user' => DB_USER, 'pass' => DB_PASS, 'name' => DB_NAME));
    Registry::set('pronto:db:main', $db);
} else {
    require_once DIR_FS_APP . DS . 'config' . DS . 'databases.php';
    foreach ($DATABASES as $key => $dbcfg) {
        $db =& Factory::db($dbcfg);
        Registry::set('pronto:db:' . $key, $db);
    }
    // we leave $db set for scripts that expect it
    unset($key, $dbcfg);
}
// TODO: this should be unset, left for back-compat for now...
//unset($db);
/************************************************************************
 * INTERNATIONALIZATION
 ************************************************************************/
$i18n = new I18N();
$i18n->autoset_language('en');
define('LANG', $i18n->get_language());
Registry::set('pronto:i18n', $i18n);
unset($i18n);
Ejemplo n.º 3
0
 /**
  * 数据库修复、优化
  */
 public function public_repair()
 {
     $tables = isset($_POST['tables']) ? $_POST['tables'] : trim($_GET['tables']);
     $operation = trim($_GET['operation']);
     $pdo_name = trim($_GET['pdo_name']);
     $this->db = Factory::db($pdo_name);
     $tables = is_array($tables) ? implode(',', $tables) : $tables;
     if ($tables && in_array($operation, array('repair', 'optimize'))) {
         $this->db->query("{$operation} TABLE {$tables}");
         showmessage(L('operation_success'), '?app=admin&controller=database&action=export&pdoname=' . $pdo_name);
     } elseif ($tables && $operation == 'showcreat') {
         $structure = $this->db->query("SHOW CREATE TABLE {$tables}");
         $structure = $structure[0]['Create Table'];
         $show_header = true;
         include $this->view('database_structure');
     } else {
         showmessage(L('select_tbl'), '?app=admin&controller=database&action=export&pdoname=' . $pdo_name);
     }
 }