diff --git a/classes/db/DB.class.php b/classes/db/DB.class.php index 9aca08174..a5c34c754 100644 --- a/classes/db/DB.class.php +++ b/classes/db/DB.class.php @@ -102,15 +102,13 @@ function setError($errno, $errstr) { $this->errno = $errno; $this->errstr = $errstr; - - if(__DEBUG__ && $this->errno!=0) debugPrint(sprintf("Query Fail\t#%05d : %s - %s\n\t\t%s", $GLOBALS['__dbcnt'], $errno, $errstr, $this->query)); } /** * @brief 접속되었는지 return **/ function isConnected() { - return $this->is_connected; + return $this->is_connected?true:false; } /** @@ -164,8 +162,6 @@ if(!file_exists($cache_file)) return new Object(-1, 'msg_invalid_queryid'); - if(__DEBUG__) $query_start = getMicroTime(); - if($source_args) $args = clone($source_args); $output = include($cache_file); @@ -187,14 +183,7 @@ break; } - if(__DEBUG__) { - $query_end = getMicroTime(); - $elapsed_time = $query_end - $query_start; - $GLOBALS['__db_elapsed_time__'] += $elapsed_time; - $GLOBALS['__db_queries__'] .= sprintf("\t%02d. %s (%0.4f sec)\n\t %s\n", ++$GLOBALS['__dbcnt'], $query_id, $elapsed_time, $this->query); - } - - if($this->errno!=0) return new Object($this->errno, $this->errstr); + if($this->errno!=0) return new Object($this->errno, $this->errstr); if(is_a($output, 'Object') || is_subclass_of($output, 'Object')) return $output; return new Object(); } diff --git a/classes/db/DBMysql.class.php b/classes/db/DBMysql.class.php index 353619c31..7fece0578 100644 --- a/classes/db/DBMysql.class.php +++ b/classes/db/DBMysql.class.php @@ -117,17 +117,35 @@ **/ function _query($query) { if(!$this->isConnected()) return; + $this->query = $query; + if(__DEBUG__) $query_start = getMicroTime(); + $this->setError(0,'success'); $result = @mysql_query($query, $this->fd); + if(__DEBUG__) { + $query_end = getMicroTime(); + $elapsed_time = $query_end - $query_start; + $GLOBALS['__db_elapsed_time__'] += $elapsed_time; + } + if(mysql_error()) { $this->setError(mysql_errno(), mysql_error()); + + if(__DEBUG__) { + $GLOBALS['__db_queries__'] .= sprintf("\t%02d. %s (%0.6f sec)\n\t Fail : %d\n\t\t %s\n", ++$GLOBALS['__dbcnt'], $this->query, $elapsed_time, $this->errno, $this->errstr); + } + return; } + if(__DEBUG__) { + $GLOBALS['__db_queries__'] .= sprintf("\t%02d. %s (%0.6f sec)\n", ++$GLOBALS['__dbcnt'], $this->query, $elapsed_time); + } + return $result; } diff --git a/classes/db/DBMysqli.class.php b/classes/db/DBMysqli.class.php index a2c0a41ca..2b74f8d88 100644 --- a/classes/db/DBMysqli.class.php +++ b/classes/db/DBMysqli.class.php @@ -12,8 +12,6 @@ class DBMysqli extends DB { - var $handler = null; - var $hostname = '127.0.0.1'; ///< hostname var $userid = NULL; ///< user id var $password = NULL; ///< password @@ -73,14 +71,16 @@ if(!$this->hostname || !$this->userid || !$this->password || !$this->database) return; // 접속시도 - $this->handler = new mysqli($this->hostname, $this->userid, $this->password, $this->database); + $this->fd = @mysqli_connect($this->hostname, $this->userid, $this->password, $this->database); // 접속체크 - if(mysqli_connect_error()) $this->is_connected = false; - else $this->is_connected = true; + if(mysqli_connect_error()) { + $this->setError(-1, mysqli_connect_error()); + return $this->is_connected = false; + } - // mysql의 경우 utf8임을 지정 - $this->handler->query("SET NAMES 'utf8'"); + $this->is_connected = true; + $this->_query("SET NAMES 'utf8'"); } /** @@ -88,15 +88,16 @@ **/ function close() { if(!$this->isConnected()) return; - $this->handler->close(); + @mysqli_close(); } /** * @brief 쿼리에서 입력되는 문자열 변수들의 quotation 조절 **/ function addQuotes($string) { + if(!$this->fd) return $string; if(get_magic_quotes_gpc()) $string = stripslashes(str_replace("\\","\\\\",$string)); - if(!is_numeric($string)) $string = $this->handler->real_escape_string($string); + if(!is_numeric($string)) $string = mysqli_escape_string($this->fd, $string); return $string; } @@ -111,17 +112,36 @@ **/ function _query($query) { if(!$this->isConnected()) return; + $this->query = $query; + if(__DEBUG__) $query_start = getMicroTime(); + $this->setError(0,'success'); - $result = $this->handler->query($query); + $result = mysqli_query($this->fd,$query); + + if(__DEBUG__) { + $query_end = getMicroTime(); + $elapsed_time = $query_end - $query_start; + $GLOBALS['__db_elapsed_time__'] += $elapsed_time; + } + + if(mysqli_errno($this->fd)) { + + $this->setError(mysqli_errno($this->fd), mysqli_error($this->fd)); + + if(__DEBUG__) { + $GLOBALS['__db_queries__'] .= sprintf("\t%02d. %s (%0.6f sec)\n\t Fail : %d\n\t\t %s\n", ++$GLOBALS['__dbcnt'], $this->query, $elapsed_time, $this->errno, $this->errstr); + } - if($this->handler->error) { - $this->setError($this->handler->errno, $this->handler->error); return; } + if(__DEBUG__) { + $GLOBALS['__db_queries__'] .= sprintf("\t%02d. %s (%0.6f sec)\n", ++$GLOBALS['__dbcnt'], $this->query, $elapsed_time); + } + return $result; } @@ -129,18 +149,27 @@ * @brief 트랜잭션 시작 **/ function begin() { + if(!$this->is_connected || $this->transaction_started) return; + $this->_query('begin'); + $this->transaction_started = true; } /** * @brief 롤백 **/ function rollback() { + if(!$this->is_connected || !$this->transaction_started) return; + $this->_query('rollback'); + $this->transaction_started = false; } /** * @brief 커밋 **/ function commit() { + if(!$this->is_connected || !$this->transaction_started) return; + $this->_query('commit'); + $this->transaction_started = false; } /** @@ -149,7 +178,7 @@ function _fetch($result) { if($this->isError() || !$result) return; - while($tmp = $result->fetch_object()) { + while($tmp = mysqli_fetch_object($result)) { $output[] = $tmp; } if(count($output)==1) return $output[0]; @@ -162,7 +191,7 @@ function getNextSequence() { $query = sprintf("insert into `%ssequence` (seq) values ('')", $this->prefix); $this->_query($query); - return $this->handler->insert_id; + return mysqli_insert_id($this->fd); } /** @@ -254,7 +283,7 @@ } } - $schema = sprintf('create table `%s` (%s%s) %s;', $this->addQuotes($table_name), "\n", implode($column_schema,",\n"), "ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci"); + $schema = sprintf('create table `%s` (%s%s) %s;', $this->addQuotes($table_name), "\n", implode($column_schema,",\n"), "type=innodb CHARACTER SET utf8 COLLATE utf8_general_ci"); $output = $this->_query($schema); if(!$output) return false; diff --git a/classes/db/DBSqlite2.class.php b/classes/db/DBSqlite2.class.php index a57e165c2..6505d36db 100644 --- a/classes/db/DBSqlite2.class.php +++ b/classes/db/DBSqlite2.class.php @@ -65,7 +65,6 @@ // 데이터 베이스 파일 접속 시도 $this->fd = sqlite_open($this->database, 0666, &$error); if(!file_exists($this->database) || $error) { - //$this->setError(-1,'permission denied to access database'); $this->setError(-1,$error); $this->is_connected = false; return; @@ -133,14 +132,33 @@ if(!$this->isConnected()) return false; $this->query = $query; + + if(__DEBUG__) $query_start = getMicroTime(); + $this->setError(0,'success'); $result = @sqlite_query($query, $this->fd); + + if(__DEBUG__) { + $query_end = getMicroTime(); + $elapsed_time = $query_end - $query_start; + $GLOBALS['__db_elapsed_time__'] += $elapsed_time; + } + if(sqlite_last_error($this->fd)) { $this->setError(sqlite_last_error($this->fd), sqlite_error_string(sqlite_last_error($this->fd))); + + if(__DEBUG__) { + $GLOBALS['__db_queries__'] .= sprintf("\t%02d. %s (%0.6f sec)\n\t Fail : %d\n\t\t %s\n", ++$GLOBALS['__dbcnt'], $this->query, $elapsed_time, $this->errno, $this->errstr); + } + return false; } + if(__DEBUG__) { + $GLOBALS['__db_queries__'] .= sprintf("\t%02d. %s (%0.6f sec)\n", ++$GLOBALS['__dbcnt'], $this->query, $elapsed_time); + } + if($result) return $result; return true; } @@ -260,15 +278,15 @@ if(count($unique_list)) { foreach($unique_list as $key => $val) { - $query = sprintf('CREATE UNIQUE INDEX IF NOT EXISTS %s (%s)', $key, implode(',',$val)); - $this->_query($schema); + $query = sprintf('CREATE UNIQUE INDEX %s_%s ON %s (%s)', $this->addQuotes($table_name), $key, $this->addQuotes($table_name), implode(',',$val)); + $this->_query($query); } } - if(count($unique_list)) { - foreach($unique_list as $key => $val) { - $query = sprintf('CREATE INDEX IF NOT EXISTS %s (%s)', $key, implode(',',$val)); - $this->_query($schema); + if(count($index_list)) { + foreach($index_list as $key => $val) { + $query = sprintf('CREATE INDEX %s_%s ON %s (%s)', $this->addQuotes($table_name), $key, $this->addQuotes($table_name), implode(',',$val)); + $this->_query($query); } } } diff --git a/classes/db/DBSqlite3_pdo.class.php b/classes/db/DBSqlite3_pdo.class.php index 85b1e66dd..b89e54785 100644 --- a/classes/db/DBSqlite3_pdo.class.php +++ b/classes/db/DBSqlite3_pdo.class.php @@ -13,8 +13,6 @@ var $bind_idx = 0; var $bind_vars = array(); - var $debugDetail = false; - var $database = NULL; ///< database var $prefix = 'zb'; ///< 제로보드에서 사용할 테이블들의 prefix (한 DB에서 여러개의 제로보드 설치 가능) @@ -155,19 +153,35 @@ function _execute() { if(!$this->isConnected() || !$this->stmt) return; + if(__DEBUG__) $query_start = getMicroTime(); + $this->stmt->execute(); - if($this->debugDetail && $this->stmt->errorCode()!='00000') debugPrint($this->query."\n".$this->stmt->errorCode()." : ".print_r($this->stmt->errorInfo(),true)."\n".print_r($this->bind_vars,true)); + if(__DEBUG__) { + $query_end = getMicroTime(); + $elapsed_time = $query_end - $query_start; + $GLOBALS['__db_elapsed_time__'] += $elapsed_time; + } $this->bind_idx = 0; $this->bind_vars = 0; if($this->stmt->errorCode()!='00000') { $this->setError($this->stmt->errorCode(),print_r($this->stmt->errorInfo(),true)); + + if(__DEBUG__) { + $GLOBALS['__db_queries__'] .= sprintf("\t%02d. %s (%0.6f sec)\n\t Fail : %d\n\t\t %s\n", ++$GLOBALS['__dbcnt'], $this->query, $elapsed_time, $this->errno, $this->errstr); + } + $this->stmt = null; + return false; } + if(__DEBUG__) { + $GLOBALS['__db_queries__'] .= sprintf("\t%02d. %s (%0.6f sec)\n", ++$GLOBALS['__dbcnt'], $this->query, $elapsed_time); + } + $output = null; while($tmp = $this->stmt->fetch(PDO::FETCH_ASSOC)) { unset($obj); diff --git a/index.php b/index.php index 3e6605d98..fb8d72983 100644 --- a/index.php +++ b/index.php @@ -1,4 +1,5 @@ init(); $oModule = &$oModuleHandler->procModule(); $oModuleHandler->displayContent($oModule); +//debugPrint(ob_get_contents()); +//ob_end_flush(); ?> diff --git a/modules/install/install.controller.php b/modules/install/install.controller.php index 58d2c3d08..0314ab2b4 100644 --- a/modules/install/install.controller.php +++ b/modules/install/install.controller.php @@ -35,9 +35,13 @@ // DB접속이 가능한지 체크 if(!$oDB->isConnected()) return new Object(-1, 'msg_dbconnect_failed'); + $oDB->begin(); + // 모든 모듈의 설치 $this->installDownloadedModule(); + $oDB->commit(); + // config 파일 생성 if(!$this->makeConfigFile()) return new Object(-1, 'msg_install_failed'); @@ -104,8 +108,7 @@ * * 모든 module의 schemas 디렉토리를 확인하여 schema xml을 이용, 테이블 생성 **/ - function installDownloadedModule() { - + function installDownloadedModule() { // 수동으로 설치를 할 목록 $manual_modules = array('install','module'); diff --git a/modules/install/lang/ko.lang.php b/modules/install/lang/ko.lang.php index ad473b015..c9c402409 100644 --- a/modules/install/lang/ko.lang.php +++ b/modules/install/lang/ko.lang.php @@ -40,6 +40,13 @@ $lang->cmd_install_fix_checklist = '필수 조건을 설정후 다음 버튼을 눌러 주세요.'; $lang->cmd_install_next = '설치를 진행합니다'; + $lang->db_desc = array( + 'mysql' => 'mysql DB를 php의 mysql*()함수를 이용하여 사용합니다.
DB 파일은 myisam으로 생성되기에 트랜잭션이 이루어지지 않습니다.', + 'mysqli' => 'mysql DB를 php의 mysqli*()함수를 이용하여 사용합니다.
DB 파일을 INNODB로 생성하여 트랜잭션 기능을 수행할 수 있습니다.
(안정화 테스트가 되지 않았습니다)', + 'sqlite2' => '파일로 데이터를 저장하는 sqlite2를 지원합니다.
설치시 DB파일은 웹에서 접근할 수 없는 곳에 생성하여 주셔야 합니다.
(안정화 테스트가 되지 않았습니다)', + 'sqlite3_pdo' => 'PHP의 PDO로 sqlite3를 지원합니다.
설치시 DB파일은 웹에서 접근할 수 없는 곳에 생성하여 주셔야 합니다.', + ); + $lang->db_title = 'DB정보 입력'; $lang->db_type = 'DB 종류'; $lang->db_hostname = 'DB 호스트네임'; diff --git a/modules/install/tpl/check_evn.html b/modules/install/tpl/check_env.html similarity index 82% rename from modules/install/tpl/check_evn.html rename to modules/install/tpl/check_env.html index 6567e6669..df999d350 100644 --- a/modules/install/tpl/check_evn.html +++ b/modules/install/tpl/check_env.html @@ -1,12 +1,6 @@ - - - - -
{$lang->introduce_title}
- - +
@@ -34,6 +28,6 @@ {$lang->cmd_install_fix_checklist} -[{$lang->cmd_next}] +[{$lang->cmd_next}] diff --git a/modules/install/tpl/form.mysql.html b/modules/install/tpl/form.mysql.html index 1cc857a77..119894a50 100644 --- a/modules/install/tpl/form.mysql.html +++ b/modules/install/tpl/form.mysql.html @@ -24,7 +24,7 @@ diff --git a/modules/install/tpl/form.mysqli.html b/modules/install/tpl/form.mysqli.html index 1cc857a77..119894a50 100644 --- a/modules/install/tpl/form.mysqli.html +++ b/modules/install/tpl/form.mysqli.html @@ -24,7 +24,7 @@ diff --git a/modules/install/tpl/select_db.html b/modules/install/tpl/select_db.html index 60389f99f..a31b609c4 100644 --- a/modules/install/tpl/select_db.html +++ b/modules/install/tpl/select_db.html @@ -6,20 +6,24 @@ + +
{$lang->install_condition_title}
{$lang->db_password} - +
{$lang->db_password} - +
- - - - -
{$lang->db_type} - -
+ {$lang->db_type} + + + + checked="true"/> + {$lang->db_desc[$val]} + + + + + + +