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

This commit is contained in:
zero 2007-04-05 02:50:09 +00:00
parent 0558e2c6be
commit 2577bb60b7
5 changed files with 256 additions and 151 deletions

View file

@ -1,17 +1,17 @@
<?php <?php
/** /**
* @class DB * @class DB
* @author zero (zero@nzeo.com) * @author zero (zero@nzeo.com)
* @brief DB* 상위 클래스 * @brief DB* 상위 클래스
* @version 0.1 * @version 0.1
* *
* 제로보드의 DB 사용은 xml을 이용하여 이루어짐을 원칙으로 한다. * 제로보드의 DB 사용은 xml을 이용하여 이루어짐을 원칙으로 한다.
* xml의 종류에는 query xml, schema xml이 있다. * xml의 종류에는 query xml, schema xml이 있다.
* query xml의 경우 DB::executeQuery() method를 이용하여 xml파일을 php code로 compile한 후에 실행이 된다. * query xml의 경우 DB::executeQuery() method를 이용하여 xml파일을 php code로 compile한 후에 실행이 된다.
* query xml은 고유한 query id를 가지며 생성은 module에서 이루어진다. * query xml은 고유한 query id를 가지며 생성은 module에서 이루어진다.
* *
* queryid = 모듈.쿼리명 * queryid = 모듈.쿼리명
**/ **/
class DB { class DB {
@ -23,6 +23,8 @@
var $errstr = ''; ///< 에러 발생시 에러 메세지 var $errstr = ''; ///< 에러 발생시 에러 메세지
var $query = ''; ///< 가장 최근에 수행된 query string var $query = ''; ///< 가장 최근에 수행된 query string
var $transaction_started = false;
var $is_connected = false; ///< DB에 접속이 되었는지에 대한 flag var $is_connected = false; ///< DB에 접속이 되었는지에 대한 flag
var $supported_list = array(); ///< 지원하는 DB의 종류, classes/DB/DB***.class.php 를 이용하여 동적으로 작성됨 var $supported_list = array(); ///< 지원하는 DB의 종류, classes/DB/DB***.class.php 를 이용하여 동적으로 작성됨
@ -83,7 +85,6 @@
if(!$oDB || !$oDB->isSupported()) continue; if(!$oDB || !$oDB->isSupported()) continue;
$this->supported_list[] = $db_type; $this->supported_list[] = $db_type;
} }
return $this->supported_list; return $this->supported_list;

View file

@ -1,12 +1,12 @@
<?php <?php
/** /**
* @class DBMysql * @class DBMysql
* @author zero (zero@nzeo.com) * @author zero (zero@nzeo.com)
* @brief MySQL DBMS를 이용하기 위한 class * @brief MySQL DBMS를 이용하기 위한 class
* @version 0.1 * @version 0.1
* *
* mysql handling class * mysql handling class
**/ **/
class DBMysql extends DB { class DBMysql extends DB {
@ -131,6 +131,24 @@
return $result; return $result;
} }
/**
* @brief 트랜잭션 시작
**/
function begin() {
}
/**
* @brief 롤백
**/
function rollback() {
}
/**
* @brief 커밋
**/
function commit() {
}
/** /**
* @brief 결과를 fetch * @brief 결과를 fetch
**/ **/

View file

@ -1,14 +1,14 @@
<?php <?php
/** /**
* @class DBMysqli * @class DBMysqli
* @author zero (zero@nzeo.com) * @author zero (zero@nzeo.com)
* @brief MySQLi DBMS를 이용하기 위한 class * @brief MySQLi DBMS를 이용하기 위한 class
* @version 0.1 * @version 0.1
* @todo mysqli 미구현 (mysql과 같은 처리..) * @todo mysqli 미구현 (mysql과 같은 처리..)
* *
* mysqli의 prepare, bind param등을 사용하려고 만들었으나.... * mysqli의 prepare, bind param등을 사용하려고 만들었으나....
* 문제는 bind_param 시에 mixed var를 eval이 아닌 방법으로 구현할 방법을 찾지 못했음. * 문제는 bind_param 시에 mixed var를 eval이 아닌 방법으로 구현할 방법을 찾지 못했음.
**/ **/
class DBMysqli extends DB { class DBMysqli extends DB {
@ -125,6 +125,24 @@
return $result; return $result;
} }
/**
* @brief 트랜잭션 시작
**/
function begin() {
}
/**
* @brief 롤백
**/
function rollback() {
}
/**
* @brief 커밋
**/
function commit() {
}
/** /**
* @brief 결과를 fetch * @brief 결과를 fetch
**/ **/

View file

@ -1,12 +1,12 @@
<?php <?php
/** /**
* @class DBSqlite2 * @class DBSqlite2
* @author zero (zero@nzeo.com) * @author zero (zero@nzeo.com)
* @brief SQLite ver 2.x 이용하기 위한 class * @brief SQLite ver 2.x 이용하기 위한 class
* @version 0.1 * @version 0.1
* *
* sqlite handling class (sqlite ver 2.x) * sqlite handling class (sqlite ver 2.x)
**/ **/
class DBSqlite2 extends DB { class DBSqlite2 extends DB {
@ -75,6 +75,33 @@
$this->is_connected = true; $this->is_connected = true;
} }
/**
* @brief 트랜잭션 시작
**/
function begin() {
if(!$this->is_connected || $this->transaction_started) return;
if($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;
}
/** /**
* @brief DB접속 해제 * @brief DB접속 해제
**/ **/
@ -103,22 +130,19 @@
* return\n * return\n
**/ **/
function _query($query) { function _query($query) {
if(!$this->isConnected()) return; if(!$this->isConnected()) return false;
$this->query = $query; $this->query = $query;
$this->setError(0,'success'); $this->setError(0,'success');
@sqlite_query("BEGIN;", $this->fd);
$result = @sqlite_query($query, $this->fd); $result = @sqlite_query($query, $this->fd);
if(sqlite_last_error($this->fd)) { if(sqlite_last_error($this->fd)) {
@sqlite_query("ROLLBACK;", $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)));
return; return false;
} else {
@sqlite_query("COMMIT;", $this->fd);
} }
return $result; if($result) return $result;
return true;
} }
/** /**
@ -210,7 +234,7 @@
$auto_increment = $column->attrs->auto_increment; $auto_increment = $column->attrs->auto_increment;
if($auto_increment) { if($auto_increment) {
$column_schema[] = sprintf('%s %s%s', $column_schema[] = sprintf('%s %s %s',
$name, $name,
$this->column_type[$type], $this->column_type[$type],
$auto_increment?'AUTOINCREMENT':'' $auto_increment?'AUTOINCREMENT':''
@ -232,25 +256,21 @@
} }
$schema = sprintf('CREATE TABLE %s (%s%s) ;', $this->addQuotes($table_name)," ", implode($column_schema,", ")); $schema = sprintf('CREATE TABLE %s (%s%s) ;', $this->addQuotes($table_name)," ", implode($column_schema,", "));
$output = $this->_query($schema); $this->_query($schema);
if(!$output) return false;
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 IF NOT EXISTS %s (%s)', $key, implode(',',$val));
$output = $this->_query($schema); $this->_query($schema);
if(!$output) return false;
} }
} }
if(count($unique_list)) { if(count($unique_list)) {
foreach($unique_list as $key => $val) { foreach($unique_list as $key => $val) {
$query = sprintf('CREATE INDEX IF NOT EXISTS %s (%s)', $key, implode(',',$val)); $query = sprintf('CREATE INDEX IF NOT EXISTS %s (%s)', $key, implode(',',$val));
$output = $this->_query($schema); $this->_query($schema);
if(!$output) return false;
} }
} }
} }
/** /**
@ -301,6 +321,7 @@
} }
$query = sprintf("INSERT INTO %s%s (%s) VALUES (%s);", $this->prefix, $table, implode(',',$key_list), implode(',', $val_list)); $query = sprintf("INSERT INTO %s%s (%s) VALUES (%s);", $this->prefix, $table, implode(',',$key_list), implode(',', $val_list));
return $this->_query($query); return $this->_query($query);
} }

View file

@ -1,45 +1,37 @@
<?php <?php
/** /**
* @class DBMysqli * @class DBSqlite3_pdo
* @author zero (zero@nzeo.com) * @author zero (zero@nzeo.com)
* @brief MySQLi DBMS를 이용하기 위한 class * @brief SQLite3를 PDO로 이용하여 class
* @version 0.1 * @version 0.1
* @todo mysqli 미구현 (mysql과 같은 처리..) **/
*
* mysqli의 prepare, bind param등을 사용하려고 만들었으나....
* 문제는 bind_param 시에 mixed var를 eval이 아닌 방법으로 구현할 방법을 찾지 못했음.
**/
class DBMysqli extends DB { class DBSqlite3_pdo extends DB {
var $handler = null; var $handler = NULL;
var $hostname = '127.0.0.1'; ///< hostname
var $userid = NULL; ///< user id
var $password = NULL; ///< password
var $database = NULL; ///< database var $database = NULL; ///< database
var $prefix = 'zb'; ///< 제로보드에서 사용할 테이블들의 prefix (한 DB에서 여러개의 제로보드 설치 가능) var $prefix = 'zb'; ///< 제로보드에서 사용할 테이블들의 prefix (한 DB에서 여러개의 제로보드 설치 가능)
/** /**
* @brief mysql에서 사용될 column type * @brief sqlite3 에서 사용될 column type
* *
* column_type은 schema/query xml에서 공통 선언된 type을 이용하기 때문에 * column_type은 schema/query xml에서 공통 선언된 type을 이용하기 때문에
* DBMS에 맞게 replace 해주어야 한다 * DBMS에 맞게 replace 해주어야 한다
**/ **/
var $column_type = array( var $column_type = array(
'bignumber' => 'bigint', 'bignumber' => 'INTEGER',
'number' => 'bigint', 'number' => 'INTEGER',
'varchar' => 'varchar', 'varchar' => 'VARHAR',
'char' => 'char', 'char' => 'CHAR',
'text' => 'text', 'text' => 'TEXT',
'bigtext' => 'longtext', 'bigtext' => 'TEXT',
'date' => 'varchar(14)', 'date' => 'VARCHAR(14)',
); );
/** /**
* @brief constructor * @brief constructor
**/ **/
function DBMysqli() { function DBSqlite3_pdo() {
$this->_setDBInfo(); $this->_setDBInfo();
$this->_connect(); $this->_connect();
} }
@ -48,7 +40,7 @@
* @brief 설치 가능 여부를 return * @brief 설치 가능 여부를 return
**/ **/
function isSupported() { function isSupported() {
if(!function_exists('mysqli_connect') || mysqli_get_client_info() < "4.1.00") return false; if(!class_exists('PDO')) return false;
return true; return true;
} }
@ -57,9 +49,6 @@
**/ **/
function _setDBInfo() { function _setDBInfo() {
$db_info = Context::getDBInfo(); $db_info = Context::getDBInfo();
$this->hostname = $db_info->db_hostname;
$this->userid = $db_info->db_userid;
$this->password = $db_info->db_password;
$this->database = $db_info->db_database; $this->database = $db_info->db_database;
$this->prefix = $db_info->db_table_prefix; $this->prefix = $db_info->db_table_prefix;
if(!substr($this->prefix,-1)!='_') $this->prefix .= '_'; if(!substr($this->prefix,-1)!='_') $this->prefix .= '_';
@ -70,25 +59,54 @@
**/ **/
function _connect() { function _connect() {
// db 정보가 없으면 무시 // db 정보가 없으면 무시
if(!$this->hostname || !$this->userid || !$this->password || !$this->database) return; if(!$this->database) return;
// 접속시도 // 데이터 베이스 파일 접속 시도
$this->handler = new mysqli($this->hostname, $this->userid, $this->password, $this->database); $this->handler = new PDO('sqlite:'.$this->database);
if(!file_exists($this->database) || $error) {
$this->setError(-1,'permission denied to access database');
//$this->setError(-1,$error);
$this->is_connected = false;
return;
}
// 접속체크 // 접속체크
if(mysqli_connect_error()) $this->is_connected = false; $this->is_connected = true;
else $this->is_connected = true;
// mysql의 경우 utf8임을 지정
$this->handler->query("SET NAMES 'utf8'");
} }
/**
* @brief 트랜잭션 시작
**/
function begin() {
if(!$this->is_connected || $this->transaction_started) return;
if($this->handler->beginTransaction()) $this->transaction_started = true;
}
/**
* @brief 롤백
**/
function rollback() {
if(!$this->is_connected || $this->transaction_started) return;
$this->handler->rollBack();
$this->transaction_started = false;
}
/**
* @brief 커밋
**/
function commit() {
if(!$this->is_connected || $this->transaction_started) return;
$this->handler->commit();
$this->transaction_started = false;
}
/** /**
* @brief DB접속 해제 * @brief DB접속 해제
**/ **/
function close() { function close() {
if(!$this->isConnected()) return; if(!$this->isConnected()) return;
$this->handler->close();
} }
/** /**
@ -96,7 +114,7 @@
**/ **/
function addQuotes($string) { function addQuotes($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 = $this->handler->quote("'","''", $string);
return $string; return $string;
} }
@ -111,17 +129,16 @@
**/ **/
function _query($query) { function _query($query) {
if(!$this->isConnected()) return; if(!$this->isConnected()) return;
$this->query = $query;
$this->query = $query;
$this->setError(0,'success'); $this->setError(0,'success');
$result = $this->handler->query($query); try {
$result = $this->handler->query($query);
if($this->handler->error) { } catch (PDOException $e) {
$this->setError($this->handler->errno, $this->handler->error); $this->setError($e->getCode(), $e->getMessage());
return; return;
} }
return $result; return $result;
} }
@ -131,30 +148,36 @@
function _fetch($result) { function _fetch($result) {
if($this->errno!=0 || !$result) return; if($this->errno!=0 || !$result) return;
while($tmp = $result->fetch_object()) { foreach($result as $tmp) {
$output[] = $tmp; unset($obj);
foreach($tmp as $key => $val) {
$pos = strpos($key, '.');
if($pos) $key = substr($key, $pos+1);
$obj->{$key} = $val;
}
$output[] = $obj;
} }
if(count($output)==1) return $output[0]; if(count($output)==1) return $output[0];
return $output; return $output;
} }
/** /**
* @brief 1 증가되는 sequence값을 return (mysql의 auto_increment는 sequence테이블에서만 사용) * @brief 1 증가되는 sequence값을 return
**/ **/
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->handler->query($query);
return $this->handler->insert_id; return $this->handler->lastInsertId();
} }
/** /**
* @brief 테이블 기생성 여부 return * @brief 테이블 기생성 여부 return
**/ **/
function isTableExists($target_name) { function isTableExists($target_name) {
$query = sprintf("show tables like '%s%s'", $this->prefix, $this->addQuotes($target_name)); $query = sprintf('pragma table_info(%s%s)', $this->prefix, $this->addQuotes($target_name));
$result = $this->_query($query); $result = $this->handler->query($query);
$tmp = $this->_fetch($result); if(count($result)==0) return false;
if(!$tmp) return false;
return true; return true;
} }
@ -198,7 +221,8 @@
foreach($columns as $column) { foreach($columns as $column) {
$name = $column->attrs->name; $name = $column->attrs->name;
$type = $column->attrs->type; $type = $column->attrs->type;
$size = $column->attrs->size; if(strtoupper($this->column_type[$type])=='INTEGER') $size = '';
else $size = $column->attrs->size;
$notnull = $column->attrs->notnull; $notnull = $column->attrs->notnull;
$primary_key = $column->attrs->primary_key; $primary_key = $column->attrs->primary_key;
$index = $column->attrs->index; $index = $column->attrs->index;
@ -206,47 +230,55 @@
$default = $column->attrs->default; $default = $column->attrs->default;
$auto_increment = $column->attrs->auto_increment; $auto_increment = $column->attrs->auto_increment;
$column_schema[] = sprintf('`%s` %s%s %s %s %s', if($auto_increment) {
$name, $column_schema[] = sprintf('%s %s PRIMARY KEY %s',
$this->column_type[$type], $name,
$size?'('.$size.')':'', $this->column_type[$type],
$default?"default '".$default."'":'', $auto_increment?'AUTOINCREMENT':''
$notnull?'not null':'', );
$auto_increment?'auto_increment':'' } else {
); $column_schema[] = sprintf('%s %s%s %s %s %s %s',
$name,
$this->column_type[$type],
$size?'('.$size.')':'',
$notnull?'NOT NULL':'',
$primary_key?'PRIMARY KEY':'',
$default?"DEFAULT '".$default."'":'',
$auto_increment?'AUTOINCREMENT':''
);
}
if($primary_key) $primary_list[] = $name; if($unique) $unique_list[$unique][] = $name;
else if($unique) $unique_list[$unique][] = $name;
else if($index) $index_list[$index][] = $name; else if($index) $index_list[$index][] = $name;
} }
if(count($primary_list)) { $schema = sprintf('CREATE TABLE %s (%s%s) ;', $this->addQuotes($table_name)," ", implode($column_schema,", "));
$column_schema[] = sprintf("primary key (%s)", '`'.implode($primary_list,'`,`').'`'); $output = $this->_query($schema);
if(!$output) return false;
if(count($unique_list)) {
foreach($unique_list as $key => $val) {
$query = sprintf('CREATE UNIQUE INDEX IF NOT EXISTS %s (%s)', $key, implode(',',$val));
$output = $this->_query($schema);
if(!$output) return false;
}
} }
if(count($unique_list)) { if(count($unique_list)) {
foreach($unique_list as $key => $val) { foreach($unique_list as $key => $val) {
$column_schema[] = sprintf("unique %s (%s)", $key, '`'.implode($val,'`,`').'`'); $query = sprintf('CREATE INDEX IF NOT EXISTS %s (%s)', $key, implode(',',$val));
$output = $this->_query($schema);
if(!$output) return false;
} }
} }
if(count($index_list)) {
foreach($index_list as $key => $val) {
$column_schema[] = sprintf("index %s (%s)", $key, '`'.implode($val,'`,`').'`');
}
}
$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");
$output = $this->_query($schema);
if(!$output) return false;
} }
/** /**
* @brief 테이블 삭제 * @brief 테이블 삭제
**/ **/
function dropTable($target_name) { function dropTable($target_name) {
$query = sprintf('drop table `%s%s`;', $this->prefix, $this->addQuotes($target_name)); $query = sprintf('DROP TABLE %s%s;', $this->prefix, $this->addQuotes($target_name));
$this->_query($query); $this->_query($query);
} }
@ -254,7 +286,7 @@
* @brief 테이블의 이름 변경 * @brief 테이블의 이름 변경
**/ **/
function renameTable($source_name, $targe_name) { function renameTable($source_name, $targe_name) {
$query = sprintf("alter table `%s%s` rename `%s%s`;", $this->prefix, $this->addQuotes($source_name), $this->prefix, $this->addQuotes($targe_name)); $query = sprintf("ALTER TABLE %s%s RENAME TO %s%s;", $this->prefix, $this->addQuotes($source_name), $this->prefix, $this->addQuotes($targe_name));
$this->_query($query); $this->_query($query);
} }
@ -262,7 +294,7 @@
* @brief 테이블을 비움 * @brief 테이블을 비움
**/ **/
function truncateTable($target_name) { function truncateTable($target_name) {
$query = sprintf("truncate table `%s%s`;", $this->prefix, $this->addQuotes($target_name)); $query = sprintf("VACUUM %s%s;", $this->prefix, $this->addQuotes($target_name));
$this->_query($query); $this->_query($query);
} }
@ -282,12 +314,16 @@
foreach($column as $key => $val) { foreach($column as $key => $val) {
$key_list[] = $key; $key_list[] = $key;
if(in_array($key, $pass_quotes)) $val_list[] = $this->addQuotes($val); $val_list[] = $this->addQuotes($val);
else $val_list[] = '\''.$this->addQuotes($val).'\''; $prepare_list[] = '?';
} }
$query = sprintf("insert into `%s%s` (%s) values (%s);", $this->prefix, $table, '`'.implode('`,`',$key_list).'`', implode(',', $val_list)); $query = sprintf("INSERT INTO %s%s (%s) VALUES (%s);", $this->prefix, $table, implode(',',$prepare_list));
return $this->_query($query); $stmt = $this->handler->prepare($query);
$val_count = count($val_list);
for($i=0;$i<$val_count;$i++) $stmt->bindParam($i+1, $val_list[$i]);
return $stmt->execute();
} }
/** /**
@ -299,17 +335,22 @@
foreach($column as $key => $val) { foreach($column as $key => $val) {
// args에 아예 해당 key가 없으면 패스 // args에 아예 해당 key가 없으면 패스
if(!isset($args->{$key})) continue; if(!isset($args->{$key})) continue;
if(in_array($key, $pass_quotes)) $update_list[] = sprintf('`%s` = %s', $key, $this->addQuotes($val));
else $update_list[] = sprintf('`%s` = \'%s\'', $key, $this->addQuotes($val)); if(in_array($key, $pass_quotes)) $update_list[] = sprintf('%s = ?', $key, $this->addQuotes($val));
$val_list[] = $this->addQuotes($val);
}
} }
if(!count($update_list)) return; if(!count($update_list)) return;
$update_query = implode(',',$update_list); $update_query = implode(',',$update_list);
if($condition) $condition = ' WHERE '.$condition;
$query = sprintf("UPDATE %s%s SET %s %s;", $this->prefix, $table, $update_query, $condition);
if($condition) $condition = ' where '.$condition; $stmt = $this->handler->prepare($query);
$query = sprintf("update `%s%s` set %s %s;", $this->prefix, $table, $update_query, $condition); $val_count = count($val_list);
for($i=0;$i<$val_count;$i++) $stmt->bindParam($i+1, $val_list[$i]);
return $this->_query($query); return $stmt->execute();
} }
/** /**
@ -318,9 +359,9 @@
function _executeDeleteAct($tables, $condition, $pass_quotes) { function _executeDeleteAct($tables, $condition, $pass_quotes) {
$table = array_pop($tables); $table = array_pop($tables);
if($condition) $condition = ' where '.$condition; if($condition) $condition = ' WHERE '.$condition;
$query = sprintf("delete from `%s%s` %s;", $this->prefix, $table, $condition); $query = sprintf("DELETE FROM %s%s %s;", $this->prefix, $table, $condition);
return $this->_query($query); return $this->_query($query);
} }
@ -345,11 +386,11 @@
$columns = implode(',', $column_list); $columns = implode(',', $column_list);
} }
if($condition) $condition = ' where '.$condition; if($condition) $condition = ' WHERE '.$condition;
if($navigation->list_count) return $this->_getNavigationData($table, $columns, $condition, $navigation); if($navigation->list_count) return $this->_getNavigationData($table, $columns, $condition, $navigation);
$query = sprintf("select %s from %s %s", $columns, $table, $condition); $query = sprintf("SELECT %s FROM %s %s", $columns, $table, $condition);
$query .= ' '.$group_script; $query .= ' '.$group_script;
@ -357,7 +398,7 @@
foreach($navigation->index as $index_obj) { foreach($navigation->index as $index_obj) {
$index_list[] = sprintf('%s %s', $index_obj[0], $index_obj[1]); $index_list[] = sprintf('%s %s', $index_obj[0], $index_obj[1]);
} }
if(count($index_list)) $query .= ' order by '.implode(',',$index_list); if(count($index_list)) $query .= ' ORDER BY '.implode(',',$index_list);
} }
$result = $this->_query($query); $result = $this->_query($query);
@ -396,7 +437,7 @@
} }
$index = implode(',',$index_list); $index = implode(',',$index_list);
$query = sprintf('select %s from %s %s order by %s limit %d, %d', $columns, $table, $condition, $index, $start_count, $navigation->list_count); $query = sprintf('SELECT %s FROM %s %s ORDER BY %s LIMIT %d, %d', $columns, $table, $condition, $index, $start_count, $navigation->list_count);
$result = $this->_query($query); $result = $this->_query($query);
if($this->errno!=0) { if($this->errno!=0) {
$buff = new Object(); $buff = new Object();
@ -410,8 +451,14 @@
} }
$virtual_no = $total_count - ($page-1)*$navigation->list_count; $virtual_no = $total_count - ($page-1)*$navigation->list_count;
while($tmp = $result->fetch_object()) { $tmp_data = $this->_fetch($result);
$data[$virtual_no--] = $tmp; if($tmp_data) {
if(!is_array($tmp_data)) $tmp_data = array($tmp_data);
foreach($tmp_data as $tmp) {
$data[$virtual_no--] = $tmp;
}
} else {
$data = null;
} }
$buff = new Object(); $buff = new Object();