diff --git a/medoo.php b/medoo.php index b5bbe09b..85338b62 100644 --- a/medoo.php +++ b/medoo.php @@ -2,7 +2,7 @@ /*! * Medoo database framework * http://medoo.in - * Version 1.1 + * Version 1.1.1 * * Copyright 2016, Angel Lai * Released under the MIT license @@ -489,7 +489,7 @@ protected function where_clause($where) } else if ($value === 'ASC' || $value === 'DESC') { - $stack[] = '"' . str_replace('.', '"."', $column) . ' ' . $value . '"'; + $stack[] = $this->column_quote($column) . ' ' . $value; } else if (is_int($column)) { @@ -741,6 +741,11 @@ public function select($table, $join, $columns = null, $where = null) return false; } + if ($columns === '*') + { + return $query->fetchAll(PDO::FETCH_ASSOC); + } + while ($row = $query->fetch(PDO::FETCH_ASSOC)) { foreach ($columns as $key => $value) @@ -908,9 +913,13 @@ public function replace($table, $columns, $search = null, $replace = null, $wher return $this->exec('UPDATE ' . $this->table_quote($table) . ' SET ' . $replace_query . $this->where_clause($where)); } - public function get($table, $join = null, $column = null, $where = null) + public function get($table, $join = null, $columns = null, $where = null) { - $query = $this->query($this->select_context($table, $join, $column, $where) . ' LIMIT 1'); + $column = $where == null ? $join : $columns; + + $is_single_column = (is_string($column) && $column !== '*'); + + $query = $this->query($this->select_context($table, $join, $columns, $where) . ' LIMIT 1'); if ($query) { @@ -918,14 +927,31 @@ public function get($table, $join = null, $column = null, $where = null) if (isset($data[ 0 ])) { - $column = $where == null ? $join : $column; + if ($is_single_column) + { + return $data[ 0 ][ preg_replace('/^[\w]*\./i', "", $column) ]; + } + + if ($column === '*') + { + return $data[ 0 ]; + } + + $stack = array(); - if (is_string($column) && $column != '*') + foreach ($columns as $key => $value) { - return $data[ 0 ][ $column ]; + if (is_array($value)) + { + $this->data_map(0, $key, $value, $data[ 0 ], $stack); + } + else + { + $this->data_map(0, $key, preg_replace('/^[\w]*\./i', "", $value), $data[ 0 ], $stack); + } } - return $data[ 0 ]; + return $stack[ 0 ]; } else {