public function select($table, $condition = "", $item = "", $groupby = "", $orderby = "", $leftjoin = "")
{
//TABLE
$table = $this->__array2string($table, true);
//condition
$condiStr = $this->__quote($condition, "AND");
if ($condiStr != "") {
$condiStr = " WHERE " . $condiStr;
}
//ITEM
if (empty($item)) {
$item = "*";
} else {
$item = $this->__array2string($item, true);
}
//GROUPBY
if (!empty($groupby)) {
$groupby = "GROUP BY " . $this->__array2string($groupby);
}
//LEFTJOIN
$join = "";
if (!empty($leftjoin)) {
if (is_array($leftjoin) || is_object($leftjoin)) {
foreach ($leftjoin as $key => $value) {
$join .= " LEFT JOIN {$key} ON {$value} ";
}
} else {
$join = " LEFT JOIN {$leftjoin}";
}
}
//{{{ ORDERBY
$orderby_sql = "";
if (!empty($orderby)) {
if (is_array($orderby) || is_object($orderby)) {
$orderby_sql_tmp = array();
foreach ($orderby as $key => $value) {
if (!is_numeric($key)) {
$orderby_sql_tmp[] = $this->__addsqlslashes($key) . " " . $value;
} else {
$orderby_sql_tmp[] = $this->__addsqlslashes($value);
}
}
if (count($orderby_sql_tmp) > 0) {
$orderby_sql = " ORDER BY " . implode(",", $orderby_sql_tmp);
}
} else {
$orderby_sql = " ORDER BY {$orderby}";
}
}
/*
*/
//}}}
$limit_sql = "";
if ($this->limit > 0) {
$limit = ($this->page - 1) * $this->limit;
$limit_sql = "LIMIT {$limit},{$this->limit}";
}
$sql = "SELECT {$item} FROM ({$table}) {$join} {$condiStr} {$groupby} {$orderby_sql} {$limit_sql}";
$start = microtime(true);
$result = $this->__query($sql);
if ($result !== false) {
$data = new DbData();
$data->page = $this->page;
$data->limit = $this->limit;
$data->items = $result;
$data->pageSize = count($data->items);
//{{{
if ($this->count == true) {
$countsql = "SELECT count(1) totalSize FROM ({$table}){$join} {$condiStr} {$groupby}";
$result_count = $this->__query($countsql);
if (!empty($result_count[0])) {
$data->totalSize = $result_count[0]['totalSize'];
if ($this->limit > 0) {
$data->totalPage = ceil($data->totalSize / $data->limit);
} else {
$data->totalPage = 1;
}
}
}
//}}}
$end = microtime(true);
$data->totalSecond = $end - $start;
$result = $data;
}
//{{{reset
$this->setPage(1);
$this->setLimit(0);
$this->setCount(false);
//}}}
return $result;
}