git-svn-id: http://xe-core.googlecode.com/svn/trunk@1079 201d5d3c-b55e-5fd7-737f-ddc643e51545

This commit is contained in:
zero 2007-04-10 08:49:56 +00:00
parent 2a13d510fb
commit 0e53c321df
12 changed files with 140 additions and 61 deletions

View file

@ -102,15 +102,13 @@
function setError($errno, $errstr) { function setError($errno, $errstr) {
$this->errno = $errno; $this->errno = $errno;
$this->errstr = $errstr; $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 * @brief 접속되었는지 return
**/ **/
function isConnected() { 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(!file_exists($cache_file)) return new Object(-1, 'msg_invalid_queryid');
if(__DEBUG__) $query_start = getMicroTime();
if($source_args) $args = clone($source_args); if($source_args) $args = clone($source_args);
$output = include($cache_file); $output = include($cache_file);
@ -187,14 +183,7 @@
break; break;
} }
if(__DEBUG__) { if($this->errno!=0) return new Object($this->errno, $this->errstr);
$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(is_a($output, 'Object') || is_subclass_of($output, 'Object')) return $output; if(is_a($output, 'Object') || is_subclass_of($output, 'Object')) return $output;
return new Object(); return new Object();
} }

View file

@ -117,17 +117,35 @@
**/ **/
function _query($query) { function _query($query) {
if(!$this->isConnected()) return; if(!$this->isConnected()) return;
$this->query = $query; $this->query = $query;
if(__DEBUG__) $query_start = getMicroTime();
$this->setError(0,'success'); $this->setError(0,'success');
$result = @mysql_query($query, $this->fd); $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()) { if(mysql_error()) {
$this->setError(mysql_errno(), 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; return;
} }
if(__DEBUG__) {
$GLOBALS['__db_queries__'] .= sprintf("\t%02d. %s (%0.6f sec)\n", ++$GLOBALS['__dbcnt'], $this->query, $elapsed_time);
}
return $result; return $result;
} }

View file

@ -12,8 +12,6 @@
class DBMysqli extends DB { class DBMysqli extends DB {
var $handler = null;
var $hostname = '127.0.0.1'; ///< hostname var $hostname = '127.0.0.1'; ///< hostname
var $userid = NULL; ///< user id var $userid = NULL; ///< user id
var $password = NULL; ///< password var $password = NULL; ///< password
@ -73,14 +71,16 @@
if(!$this->hostname || !$this->userid || !$this->password || !$this->database) return; 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; if(mysqli_connect_error()) {
else $this->is_connected = true; $this->setError(-1, mysqli_connect_error());
return $this->is_connected = false;
}
// mysql의 경우 utf8임을 지정 $this->is_connected = true;
$this->handler->query("SET NAMES 'utf8'"); $this->_query("SET NAMES 'utf8'");
} }
/** /**
@ -88,15 +88,16 @@
**/ **/
function close() { function close() {
if(!$this->isConnected()) return; if(!$this->isConnected()) return;
$this->handler->close(); @mysqli_close();
} }
/** /**
* @brief 쿼리에서 입력되는 문자열 변수들의 quotation 조절 * @brief 쿼리에서 입력되는 문자열 변수들의 quotation 조절
**/ **/
function addQuotes($string) { function addQuotes($string) {
if(!$this->fd) return $string;
if(get_magic_quotes_gpc()) $string = stripslashes(str_replace("\\","\\\\",$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; return $string;
} }
@ -111,17 +112,36 @@
**/ **/
function _query($query) { function _query($query) {
if(!$this->isConnected()) return; if(!$this->isConnected()) return;
$this->query = $query; $this->query = $query;
if(__DEBUG__) $query_start = getMicroTime();
$this->setError(0,'success'); $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; return;
} }
if(__DEBUG__) {
$GLOBALS['__db_queries__'] .= sprintf("\t%02d. %s (%0.6f sec)\n", ++$GLOBALS['__dbcnt'], $this->query, $elapsed_time);
}
return $result; return $result;
} }
@ -129,18 +149,27 @@
* @brief 트랜잭션 시작 * @brief 트랜잭션 시작
**/ **/
function begin() { function begin() {
if(!$this->is_connected || $this->transaction_started) return;
$this->_query('begin');
$this->transaction_started = true;
} }
/** /**
* @brief 롤백 * @brief 롤백
**/ **/
function rollback() { function rollback() {
if(!$this->is_connected || !$this->transaction_started) return;
$this->_query('rollback');
$this->transaction_started = false;
} }
/** /**
* @brief 커밋 * @brief 커밋
**/ **/
function commit() { function commit() {
if(!$this->is_connected || !$this->transaction_started) return;
$this->_query('commit');
$this->transaction_started = false;
} }
/** /**
@ -149,7 +178,7 @@
function _fetch($result) { function _fetch($result) {
if($this->isError() || !$result) return; if($this->isError() || !$result) return;
while($tmp = $result->fetch_object()) { while($tmp = mysqli_fetch_object($result)) {
$output[] = $tmp; $output[] = $tmp;
} }
if(count($output)==1) return $output[0]; if(count($output)==1) return $output[0];
@ -162,7 +191,7 @@
function getNextSequence() { function getNextSequence() {
$query = sprintf("insert into `%ssequence` (seq) values ('')", $this->prefix); $query = sprintf("insert into `%ssequence` (seq) values ('')", $this->prefix);
$this->_query($query); $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); $output = $this->_query($schema);
if(!$output) return false; if(!$output) return false;

View file

@ -65,7 +65,6 @@
// 데이터 베이스 파일 접속 시도 // 데이터 베이스 파일 접속 시도
$this->fd = sqlite_open($this->database, 0666, &$error); $this->fd = sqlite_open($this->database, 0666, &$error);
if(!file_exists($this->database) || $error) { if(!file_exists($this->database) || $error) {
//$this->setError(-1,'permission denied to access database');
$this->setError(-1,$error); $this->setError(-1,$error);
$this->is_connected = false; $this->is_connected = false;
return; return;
@ -133,14 +132,33 @@
if(!$this->isConnected()) return false; if(!$this->isConnected()) return false;
$this->query = $query; $this->query = $query;
if(__DEBUG__) $query_start = getMicroTime();
$this->setError(0,'success'); $this->setError(0,'success');
$result = @sqlite_query($query, $this->fd); $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)) { if(sqlite_last_error($this->fd)) {
$this->setError(sqlite_last_error($this->fd), sqlite_error_string(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; 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; if($result) return $result;
return true; return true;
} }
@ -260,15 +278,15 @@
if(count($unique_list)) { if(count($unique_list)) {
foreach($unique_list as $key => $val) { foreach($unique_list as $key => $val) {
$query = sprintf('CREATE UNIQUE INDEX IF NOT EXISTS %s (%s)', $key, implode(',',$val)); $query = sprintf('CREATE UNIQUE INDEX %s_%s ON %s (%s)', $this->addQuotes($table_name), $key, $this->addQuotes($table_name), implode(',',$val));
$this->_query($schema); $this->_query($query);
} }
} }
if(count($unique_list)) { if(count($index_list)) {
foreach($unique_list as $key => $val) { foreach($index_list as $key => $val) {
$query = sprintf('CREATE INDEX IF NOT EXISTS %s (%s)', $key, implode(',',$val)); $query = sprintf('CREATE INDEX %s_%s ON %s (%s)', $this->addQuotes($table_name), $key, $this->addQuotes($table_name), implode(',',$val));
$this->_query($schema); $this->_query($query);
} }
} }
} }

View file

@ -13,8 +13,6 @@
var $bind_idx = 0; var $bind_idx = 0;
var $bind_vars = array(); var $bind_vars = array();
var $debugDetail = false;
var $database = NULL; ///< database var $database = NULL; ///< database
var $prefix = 'zb'; ///< 제로보드에서 사용할 테이블들의 prefix (한 DB에서 여러개의 제로보드 설치 가능) var $prefix = 'zb'; ///< 제로보드에서 사용할 테이블들의 prefix (한 DB에서 여러개의 제로보드 설치 가능)
@ -155,19 +153,35 @@
function _execute() { function _execute() {
if(!$this->isConnected() || !$this->stmt) return; if(!$this->isConnected() || !$this->stmt) return;
if(__DEBUG__) $query_start = getMicroTime();
$this->stmt->execute(); $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_idx = 0;
$this->bind_vars = 0; $this->bind_vars = 0;
if($this->stmt->errorCode()!='00000') { if($this->stmt->errorCode()!='00000') {
$this->setError($this->stmt->errorCode(),print_r($this->stmt->errorInfo(),true)); $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; $this->stmt = null;
return false; return false;
} }
if(__DEBUG__) {
$GLOBALS['__db_queries__'] .= sprintf("\t%02d. %s (%0.6f sec)\n", ++$GLOBALS['__dbcnt'], $this->query, $elapsed_time);
}
$output = null; $output = null;
while($tmp = $this->stmt->fetch(PDO::FETCH_ASSOC)) { while($tmp = $this->stmt->fetch(PDO::FETCH_ASSOC)) {
unset($obj); unset($obj);

View file

@ -1,4 +1,5 @@
<?php <?php
//ob_start();
/** /**
* @file index.php * @file index.php
* @author zero (zero@zeroboard.com) * @author zero (zero@zeroboard.com)
@ -47,4 +48,6 @@
$oModuleHandler->init(); $oModuleHandler->init();
$oModule = &$oModuleHandler->procModule(); $oModule = &$oModuleHandler->procModule();
$oModuleHandler->displayContent($oModule); $oModuleHandler->displayContent($oModule);
//debugPrint(ob_get_contents());
//ob_end_flush();
?> ?>

View file

@ -35,9 +35,13 @@
// DB접속이 가능한지 체크 // DB접속이 가능한지 체크
if(!$oDB->isConnected()) return new Object(-1, 'msg_dbconnect_failed'); if(!$oDB->isConnected()) return new Object(-1, 'msg_dbconnect_failed');
$oDB->begin();
// 모든 모듈의 설치 // 모든 모듈의 설치
$this->installDownloadedModule(); $this->installDownloadedModule();
$oDB->commit();
// config 파일 생성 // config 파일 생성
if(!$this->makeConfigFile()) return new Object(-1, 'msg_install_failed'); if(!$this->makeConfigFile()) return new Object(-1, 'msg_install_failed');
@ -104,8 +108,7 @@
* *
* 모든 module의 schemas 디렉토리를 확인하여 schema xml을 이용, 테이블 생성 * 모든 module의 schemas 디렉토리를 확인하여 schema xml을 이용, 테이블 생성
**/ **/
function installDownloadedModule() { function installDownloadedModule() {
// 수동으로 설치를 할 목록 // 수동으로 설치를 할 목록
$manual_modules = array('install','module'); $manual_modules = array('install','module');

View file

@ -40,6 +40,13 @@
$lang->cmd_install_fix_checklist = '필수 조건을 설정후 다음 버튼을 눌러 주세요.'; $lang->cmd_install_fix_checklist = '필수 조건을 설정후 다음 버튼을 눌러 주세요.';
$lang->cmd_install_next = '설치를 진행합니다'; $lang->cmd_install_next = '설치를 진행합니다';
$lang->db_desc = array(
'mysql' => 'mysql DB를 php의 mysql*()함수를 이용하여 사용합니다.<br />DB 파일은 myisam으로 생성되기에 트랜잭션이 이루어지지 않습니다.',
'mysqli' => 'mysql DB를 php의 mysqli*()함수를 이용하여 사용합니다.<br />DB 파일을 INNODB로 생성하여 트랜잭션 기능을 수행할 수 있습니다.<br />(안정화 테스트가 되지 않았습니다)',
'sqlite2' => '파일로 데이터를 저장하는 sqlite2를 지원합니다.<br />설치시 DB파일은 웹에서 접근할 수 없는 곳에 생성하여 주셔야 합니다.<br />(안정화 테스트가 되지 않았습니다)',
'sqlite3_pdo' => 'PHP의 PDO로 sqlite3를 지원합니다.<br />설치시 DB파일은 웹에서 접근할 수 없는 곳에 생성하여 주셔야 합니다.',
);
$lang->db_title = 'DB정보 입력'; $lang->db_title = 'DB정보 입력';
$lang->db_type = 'DB 종류'; $lang->db_type = 'DB 종류';
$lang->db_hostname = 'DB 호스트네임'; $lang->db_hostname = 'DB 호스트네임';

View file

@ -1,12 +1,6 @@
<!--#include("header.html")--> <!--#include("header.html")-->
<table border="1"> <table border="1" width="100%">
<tr>
<td colspan="2">{$lang->introduce_title}</td>
</tr>
</table>
<table border="1">
<tr> <tr>
<td colspan="2">{$lang->install_condition_title}</td> <td colspan="2">{$lang->install_condition_title}</td>
</tr> </tr>
@ -34,6 +28,6 @@
<!--@else--> <!--@else-->
{$lang->cmd_install_fix_checklist} {$lang->cmd_install_fix_checklist}
[<a href="./">{$lang->cmd_next}</a>] [<a href="{getUrl('','act',$act)}">{$lang->cmd_next}</a>]
<!--@end--> <!--@end-->

View file

@ -24,7 +24,7 @@
<tr> <tr>
<td>{$lang->db_password}</td> <td>{$lang->db_password}</td>
<td> <td>
<input type="password" name="db_password" value="1234" /> <input type="password" name="db_password" value="dev" />
</td> </td>
</tr> </tr>
<tr> <tr>

View file

@ -24,7 +24,7 @@
<tr> <tr>
<td>{$lang->db_password}</td> <td>{$lang->db_password}</td>
<td> <td>
<input type="password" name="db_password" value="1234" /> <input type="password" name="db_password" value="dev" />
</td> </td>
</tr> </tr>
<tr> <tr>

View file

@ -6,20 +6,24 @@
<!--@if($install_enable)--> <!--@if($install_enable)-->
<form method="get" action="./"> <form method="get" action="./">
<input type="hidden" name="module" value="{$module}" />
<input type="hidden" name="act" value="dispInstallForm" /> <input type="hidden" name="act" value="dispInstallForm" />
<table border="1"> <table border="1">
<tr> <tr>
<td>{$lang->db_type}</td> <th colspan="2">{$lang->db_type}</th>
<td> </tr>
<select name="db_type"> <!--@foreach(DB::getSupportedList() as $key => $val)-->
<!--@foreach(DB::getSupportedList() as $_key => $_db_name)--> <tr>
<option value="{$_db_name}">{$_db_name}</option> <td><input type="radio" name="db_type" value="{$val}" id="db_type_{$val}" <!--@if($val=="mysql")-->checked="true"<!--@end-->/><label for="db_type_{$val}">{$val}</label></td>
<!--@end--> <td>{$lang->db_desc[$val]}</td>
</select> </tr>
</td> <!--@end-->
<td><input type="submit" value="{$lang->cmd_install_next}" /></td> <tr>
</tr> <td colspan="2"><input type="submit" value="{$lang->cmd_install_next}" /></td>
</table> </tr>
</table>
</form> </form>
<!--@else--> <!--@else-->