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) {
$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,13 +183,6 @@
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(is_a($output, 'Object') || is_subclass_of($output, 'Object')) return $output;
return new Object();

View file

@ -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;
}

View file

@ -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;

View file

@ -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);
}
}
}

View file

@ -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);

View file

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

View file

@ -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');
@ -105,7 +109,6 @@
* 모든 module의 schemas 디렉토리를 확인하여 schema xml을 이용, 테이블 생성
**/
function installDownloadedModule() {
// 수동으로 설치를 할 목록
$manual_modules = array('install','module');

View file

@ -40,6 +40,13 @@
$lang->cmd_install_fix_checklist = '필수 조건을 설정후 다음 버튼을 눌러 주세요.';
$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_type = 'DB 종류';
$lang->db_hostname = 'DB 호스트네임';

View file

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

View file

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

View file

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

View file

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