Support dameng database.
This commit is contained in:
@@ -391,6 +391,7 @@ class baseRouter
|
||||
|
||||
$this->loadClass('front', $static = true);
|
||||
$this->loadClass('filter', $static = true);
|
||||
$this->loadClass('dbh', $static = true);
|
||||
$this->loadClass('dao', $static = true);
|
||||
$this->loadClass('mobile', $static = true);
|
||||
|
||||
@@ -2747,15 +2748,11 @@ class baseRouter
|
||||
{
|
||||
if(!isset($params->driver)) self::triggerError('no pdo driver defined, it should be mysql or sqlite', __FILE__, __LINE__, $exit = true);
|
||||
if(!isset($params->user)) return false;
|
||||
if($params->driver == 'mysql')
|
||||
{
|
||||
$dsn = "mysql:host={$params->host}; port={$params->port}; dbname={$params->name}";
|
||||
}
|
||||
try
|
||||
{
|
||||
$dbPassword = helper::decryptPassword($params->password);
|
||||
|
||||
$dbh = new PDO($dsn, $params->user, $dbPassword, array(PDO::ATTR_PERSISTENT => $params->persistant));
|
||||
$dbh = new dbh($params);
|
||||
$dbh->exec("SET NAMES {$params->encoding}");
|
||||
|
||||
/*
|
||||
|
||||
@@ -0,0 +1,184 @@
|
||||
<?php
|
||||
/**
|
||||
* ZenTaoPHP的dbh类。
|
||||
* The dbh class file of ZenTaoPHP framework.
|
||||
*
|
||||
* The author disclaims copyright to this source code. In place of
|
||||
* a legal notice, here is a blessing:
|
||||
*
|
||||
* May you do good and not evil.
|
||||
* May you find forgiveness for yourself and forgive others.
|
||||
* May you share freely, never taking more than you give.
|
||||
*/
|
||||
|
||||
/**
|
||||
* DBH类。
|
||||
* DBH, database handler.
|
||||
*
|
||||
* @package lib
|
||||
*/
|
||||
class dbh
|
||||
{
|
||||
/**
|
||||
* PDO.
|
||||
*
|
||||
* @var object
|
||||
* @access private
|
||||
*/
|
||||
private $pdo;
|
||||
|
||||
/**
|
||||
* Database config.
|
||||
*
|
||||
* @var object
|
||||
* @access private
|
||||
*/
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param object $config
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($config)
|
||||
{
|
||||
$dsn = "{$config->driver}:host={$config->host}:{$config->port}";
|
||||
$pdo = new PDO($dsn, $config->user, $config->password);
|
||||
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
|
||||
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
|
||||
if($config->driver == 'mysql')
|
||||
{
|
||||
$pdo->exec("SET NAMES {$config->encoding}");
|
||||
if(isset($this->config->strictMode) and $this->config->strictMode == false) $pdo->exec("SET @@sql_mode= ''");
|
||||
}
|
||||
|
||||
$this->pdo = $pdo;
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Query sql.
|
||||
*
|
||||
* @param string $sql
|
||||
* @access public
|
||||
* @return PDOStatement|false
|
||||
*/
|
||||
public function query($sql)
|
||||
{
|
||||
return $this->pdo->query($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute sql.
|
||||
*
|
||||
* @param string $sql
|
||||
* @access public
|
||||
* @return PDOStatement|false
|
||||
*/
|
||||
public function exec($sql)
|
||||
{
|
||||
return $this->pdo->exec($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check db exits or not.
|
||||
*
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function dbExists()
|
||||
{
|
||||
switch($this->config->driver)
|
||||
{
|
||||
case 'mysql':
|
||||
$sql = "SHOW DATABASES like '{$this->config->name}'";
|
||||
break;
|
||||
case 'dm':
|
||||
$sql = "select * from dba_objects where object_type='SCH' and owner='{$this->config->name}';";
|
||||
break;
|
||||
default:
|
||||
$sql = '';
|
||||
}
|
||||
|
||||
return $this->query($sql)->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check table exits or not.
|
||||
*
|
||||
* @param string $tableName
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function tableExits($tableName)
|
||||
{
|
||||
$tableName = str_replace('`', "'", $tableName);
|
||||
$sql = "SHOW TABLES FROM {$this->config->name} like $tableName";
|
||||
switch($this->config->driver)
|
||||
{
|
||||
case 'mysql':
|
||||
$sql = "SHOW TABLES FROM {$this->config->name} like {$tableName}";
|
||||
break;
|
||||
case 'dm':
|
||||
$sql = "select * from all_tables where owner='{$this->config->name}' and table_name={$tableName};";
|
||||
break;
|
||||
default:
|
||||
$sql = '';
|
||||
}
|
||||
|
||||
return $this->query($sql)->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create database.
|
||||
*
|
||||
* @param string $version
|
||||
* @access public
|
||||
* @return PDOStatement|false
|
||||
*/
|
||||
public function createDB($version)
|
||||
{
|
||||
switch($this->config->driver == 'mysql')
|
||||
{
|
||||
case 'mysql':
|
||||
$sql = "CREATE DATABASE `{$this->config->name}`";
|
||||
if($version > 4.1) $sql .= " DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci";
|
||||
return $this->query($sql);
|
||||
|
||||
case 'dm':
|
||||
$createTableSpace = "CREATE TABLESPACE {$this->config->name} DATAFILE '{$this->config->name}.DBF' size 150 AUTOEXTEND ON";
|
||||
$createUser = "CREATE USER {$this->config->name} IDENTIFIED by {$this->config->password} DEFAULT TABLESPACE {$this->config->name} DEFAULT INDEX TABLESPACE {$this->config->name};";
|
||||
|
||||
$this->query($createTableSpace);
|
||||
return $this->query($createUser);
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Use database or schema.
|
||||
*
|
||||
* @param string $dbName
|
||||
* @access public
|
||||
* @return PDOStatement|false
|
||||
*/
|
||||
public function useDB($dbName)
|
||||
{
|
||||
switch($this->config->driver == 'mysql')
|
||||
{
|
||||
case 'mysql':
|
||||
return $this->exec("USE {$this->config->name}");
|
||||
|
||||
case 'dm':
|
||||
return $this->exec("SET SCHEMA {$this->config->name}");
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -121,6 +121,7 @@ $lang->install->chmodLinux = ' "%s" Berechtigung muss geändert werden.<br />
|
||||
|
||||
$lang->install->timezone = 'Set Timezone';
|
||||
$lang->install->defaultLang = 'Standard Sprache';
|
||||
$lang->install->dbDriver = 'Database Driver';
|
||||
$lang->install->dbHost = 'Datenbank Host';
|
||||
$lang->install->dbHostNote = 'Wenn 127.0.0.1 nicht funktioniert, versuchen Sie localhost.';
|
||||
$lang->install->dbPort = 'Datenbank Port';
|
||||
@@ -133,6 +134,11 @@ $lang->install->clearDB = 'Tabellen leeren sofern diese scon existieren.'
|
||||
$lang->install->importDemoData = 'Import Demo Daten';
|
||||
$lang->install->working = 'Work Mode';
|
||||
|
||||
$lang->install->dbDriverList = array();
|
||||
$lang->install->dbDriverList['mysql'] = 'MySQL';
|
||||
$lang->install->dbDriverList['pgsql'] = 'PostgreSQL';
|
||||
$lang->install->dbDriverList['dm'] = 'DM8';
|
||||
|
||||
$lang->install->requestTypes['GET'] = 'GET';
|
||||
$lang->install->requestTypes['PATH_INFO'] = 'PATH_INFO';
|
||||
|
||||
|
||||
@@ -121,6 +121,7 @@ $lang->install->chmodLinux = ' "%s" permison has to be changed.<br /> Run <cod
|
||||
|
||||
$lang->install->timezone = 'Set Timezone';
|
||||
$lang->install->defaultLang = 'Default Language';
|
||||
$lang->install->dbDriver = 'Database Driver';
|
||||
$lang->install->dbHost = 'Database Host';
|
||||
$lang->install->dbHostNote = 'If 127.0.0.1 is not accessible, try localhost.';
|
||||
$lang->install->dbPort = 'Host Port';
|
||||
@@ -133,6 +134,11 @@ $lang->install->clearDB = 'Clean up existing data';
|
||||
$lang->install->importDemoData = 'Import Demo Data';
|
||||
$lang->install->working = 'Operation Mode';
|
||||
|
||||
$lang->install->dbDriverList = array();
|
||||
$lang->install->dbDriverList['mysql'] = 'MySQL';
|
||||
$lang->install->dbDriverList['pgsql'] = 'PostgreSQL';
|
||||
$lang->install->dbDriverList['dm'] = 'DM8';
|
||||
|
||||
$lang->install->requestTypes['GET'] = 'GET';
|
||||
$lang->install->requestTypes['PATH_INFO'] = 'PATH_INFO';
|
||||
|
||||
|
||||
@@ -121,6 +121,7 @@ $lang->install->chmodLinux = 'Les permission de "%s" doivent être modifiées.
|
||||
|
||||
$lang->install->timezone = 'Set Timezone';
|
||||
$lang->install->defaultLang = 'Langue par défaut';
|
||||
$lang->install->dbDriver = 'Database Driver';
|
||||
$lang->install->dbHost = 'Database Serveur';
|
||||
$lang->install->dbHostNote = "If 127.0.0.1 n'est pas accessible, essayez localhost.";
|
||||
$lang->install->dbPort = 'Port Serveur';
|
||||
@@ -133,6 +134,11 @@ $lang->install->clearDB = 'Nettoyer les données existantes';
|
||||
$lang->install->importDemoData = 'Importer données de Démo';
|
||||
$lang->install->working = 'Operation Mode';
|
||||
|
||||
$lang->install->dbDriverList = array();
|
||||
$lang->install->dbDriverList['mysql'] = 'MySQL';
|
||||
$lang->install->dbDriverList['pgsql'] = 'PostgreSQL';
|
||||
$lang->install->dbDriverList['dm'] = 'DM8';
|
||||
|
||||
$lang->install->requestTypes['GET'] = 'GET';
|
||||
$lang->install->requestTypes['PATH_INFO'] = 'PATH_INFO';
|
||||
|
||||
|
||||
@@ -91,6 +91,7 @@ $lang->install->chmodLinux = ' "%s" permison has to be changed.<br /> Run <cod
|
||||
|
||||
$lang->install->timezone = 'Thiết lập Timezone';
|
||||
$lang->install->defaultLang = 'Ngôn ngữ mặc định';
|
||||
$lang->install->dbDriver = 'Database Driver';
|
||||
$lang->install->dbHost = 'Database Host';
|
||||
$lang->install->dbHostNote = 'If 127.0.0.1 không là accessible, try localhost.';
|
||||
$lang->install->dbPort = 'Host Port';
|
||||
@@ -103,6 +104,11 @@ $lang->install->clearDB = 'Clean up existing data';
|
||||
$lang->install->importDemoData = 'Nhập Demo dữ liệu';
|
||||
$lang->install->working = 'Operation chế độ';
|
||||
|
||||
$lang->install->dbDriverList = array();
|
||||
$lang->install->dbDriverList['mysql'] = 'MySQL';
|
||||
$lang->install->dbDriverList['pgsql'] = 'PostgreSQL';
|
||||
$lang->install->dbDriverList['dm'] = 'DM8';
|
||||
|
||||
$lang->install->requestTypes['GET'] = 'GET';
|
||||
$lang->install->requestTypes['PATH_INFO'] = 'PATH_INFO';
|
||||
|
||||
|
||||
@@ -121,6 +121,7 @@ $lang->install->chmodLinux = '需要修改目录 "%s" 的权限。<br />命令
|
||||
|
||||
$lang->install->timezone = '时区设置';
|
||||
$lang->install->defaultLang = '默认语言';
|
||||
$lang->install->dbDriver = 'Database Driver';
|
||||
$lang->install->dbHost = '数据库服务器';
|
||||
$lang->install->dbHostNote = '如果127.0.0.1无法访问,尝试使用localhost';
|
||||
$lang->install->dbPort = '服务器端口';
|
||||
@@ -133,6 +134,11 @@ $lang->install->clearDB = '清空现有数据';
|
||||
$lang->install->importDemoData = '导入demo数据';
|
||||
$lang->install->working = '工作方式';
|
||||
|
||||
$lang->install->dbDriverList = array();
|
||||
$lang->install->dbDriverList['mysql'] = 'MySQL';
|
||||
$lang->install->dbDriverList['pgsql'] = 'PostgreSQL';
|
||||
$lang->install->dbDriverList['dm'] = '达梦';
|
||||
|
||||
$lang->install->requestTypes['GET'] = '普通方式';
|
||||
$lang->install->requestTypes['PATH_INFO'] = '静态友好方式';
|
||||
|
||||
|
||||
+12
-54
@@ -294,20 +294,20 @@ class installModel extends model
|
||||
return $return;
|
||||
}
|
||||
|
||||
/* Get mysql version. */
|
||||
$version = $this->getMysqlVersion();
|
||||
/* Get database version. */
|
||||
$version = $this->getDatabaseVersion();
|
||||
|
||||
/* If database no exits, try create it. */
|
||||
if(!$this->dbExists())
|
||||
if(!$this->dbh->dbExists())
|
||||
{
|
||||
if(!$this->createDB($version))
|
||||
if(!$this->dbh->createDB($version))
|
||||
{
|
||||
$return->result = 'fail';
|
||||
$return->error = $this->lang->install->errorCreateDB;
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
elseif($this->tableExits() and $this->post->clearDB == false)
|
||||
elseif($this->dbh->tableExits(TABLE_CONFIG) and $this->post->clearDB == false)
|
||||
{
|
||||
$return->result = 'fail';
|
||||
$return->error = $this->lang->install->errorTableExists;
|
||||
@@ -333,6 +333,7 @@ class installModel extends model
|
||||
*/
|
||||
public function setDBParam()
|
||||
{
|
||||
$this->config->db->driver = $this->post->dbDriver;
|
||||
$this->config->db->host = $this->post->dbHost;
|
||||
$this->config->db->name = $this->post->dbName;
|
||||
$this->config->db->user = $this->post->dbUser;
|
||||
@@ -350,15 +351,9 @@ class installModel extends model
|
||||
*/
|
||||
public function connectDB()
|
||||
{
|
||||
$dsn = "mysql:host={$this->config->db->host}; port={$this->config->db->port}";
|
||||
try
|
||||
{
|
||||
$dbh = new PDO($dsn, $this->config->db->user, $this->config->db->password);
|
||||
$dbh->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
|
||||
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
$dbh->exec("SET NAMES {$this->config->db->encoding}");
|
||||
if(isset($this->config->db->strictMode) and $this->config->db->strictMode == false) $dbh->exec("SET @@sql_mode= ''");
|
||||
return $dbh;
|
||||
return new dbh($this->config->db);
|
||||
}
|
||||
catch (PDOException $exception)
|
||||
{
|
||||
@@ -367,57 +362,20 @@ class installModel extends model
|
||||
}
|
||||
|
||||
/**
|
||||
* Check db exits or not.
|
||||
*
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function dbExists()
|
||||
{
|
||||
$sql = "SHOW DATABASES like '{$this->config->db->name}'";
|
||||
return $this->dbh->query($sql)->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check table exits or not.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function tableExits()
|
||||
{
|
||||
$configTable = str_replace('`', "'", TABLE_CONFIG);
|
||||
$sql = "SHOW TABLES FROM {$this->config->db->name} like $configTable";
|
||||
return $this->dbh->query($sql)->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get mysql version.
|
||||
* Get database version.
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getMysqlVersion()
|
||||
public function getDatabaseVersion()
|
||||
{
|
||||
if($this->config->db->driver != 'mysql') return 0;
|
||||
|
||||
$sql = "SELECT VERSION() AS version";
|
||||
$result = $this->dbh->query($sql)->fetch();
|
||||
return substr($result->version, 0, 3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create database.
|
||||
*
|
||||
* @param string $version
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function createDB($version)
|
||||
{
|
||||
$sql = "CREATE DATABASE `{$this->config->db->name}`";
|
||||
if($version > 4.1) $sql .= " DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci";
|
||||
return $this->dbh->query($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create tables.
|
||||
*
|
||||
@@ -430,7 +388,7 @@ class installModel extends model
|
||||
/* Add exception handling to ensure that all SQL is executed successfully. */
|
||||
try
|
||||
{
|
||||
$this->dbh->exec("USE {$this->config->db->name}");
|
||||
$this->dbh->useDB($this->config->db->name);
|
||||
|
||||
$dbFile = $this->app->getAppRoot() . 'db' . DS . 'zentao.sql';
|
||||
$tables = explode(';', file_get_contents($dbFile));
|
||||
|
||||
@@ -31,6 +31,10 @@
|
||||
<th><?php echo $lang->install->defaultLang;?></th>
|
||||
<td><?php echo html::select('defaultLang', $config->langs, $app->getClientLang(), "class='form-control'");?></td><td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><?php echo $lang->install->dbDriver;?></th>
|
||||
<td><?php echo html::select('dbDriver', $lang->install->dbDriverList, 'mysql', "class='form-control'");?></td><td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><?php echo $lang->install->dbHost;?></th>
|
||||
<td><?php echo html::input('dbHost', $dbHost, "class='form-control'");?></td>
|
||||
|
||||
Reference in New Issue
Block a user