Beispiel #1
0
 protected function select(array $selectFields, array $param, $tables)
 {
     $limit = $order = $where = $fromTables = $like = '';
     $fields = implode(',', $selectFields);
     //处理筛选条件
     if (!Validate::isNullArray($param)) {
         $limit = isset($param['limit']) ? ' LIMIT  ' . $param['limit'] : '';
         $order = isset($param['order']) ? ' ORDER BY ' . $param['order'] : '';
         if (isset($param['where'])) {
             $isAnd = '';
             foreach ($param['where'] as $value) {
                 $isAnd .= $value . ' AND ';
             }
             $where = ' WHERE ' . substr($isAnd, 0, -4);
         }
         if (isset($param['like'])) {
             foreach ($param['like'] as $key => $value) {
                 $like = " WHERE {$key} LIKE '%{$value}%'";
             }
         }
     }
     //处理多表联查
     foreach ($tables as $value) {
         $fromTables .= $value . ' ,';
     }
     $fromTables = substr($fromTables, 0, -1);
     $sql = "SELECT {$fields} FROM {$fromTables} {$where} {$like} {$order} {$limit} ";
     $stmt = $this->execute($sql);
     $result = array();
     while (!!($obj = $stmt->fetchObject())) {
         $result[] = $obj;
     }
     return Tool::setHtmlString($result);
 }
Beispiel #2
0
 protected function select($_tables, array $_field, array $_param = array())
 {
     $_limit = '';
     $_order = '';
     $_where = '';
     $_like = '';
     if (Validate::isArray($_param) && !Validate::isNullArray($_param)) {
         $_limit = isset($_param['limit']) ? 'LIMIT ' . $_param['limit'] : '';
         $_order = isset($_param['order']) ? 'ORDER BY ' . $_param['order'] : '';
         $_where = '';
         if (isset($_param['where'])) {
             foreach ($_param['where'] as $_key => $_value) {
                 $_where .= $_value . ' AND ';
             }
             $_where = 'WHERE ' . substr($_where, 0, -4);
         }
         if (isset($_param['like'])) {
             foreach ($_param['like'] as $_key => $_value) {
                 $_like = "WHERE {$_key} LIKE '%{$_value}%'";
             }
         }
     }
     $_selectFields = implode(',', $_field);
     $_table = isset($_tables[1]) ? $_tables[0] . ',' . $_tables[1] : $_tables[0];
     $_sql = "SELECT {$_selectFields} FROM {$_table} {$_where} {$_like} {$_order} {$_limit} ";
     $_stmt = $this->execute($_sql);
     $_result = array();
     while (!!($_objs = $_stmt->fetchObject())) {
         $_result[] = $_objs;
     }
     return Tool::setHtmlString($_result);
 }