Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
catfan committed Jun 28, 2016
2 parents 697abce + e788a73 commit b1c49a9
Showing 1 changed file with 34 additions and 8 deletions.
42 changes: 34 additions & 8 deletions medoo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -908,24 +913,45 @@ 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)
{
$data = $query->fetchAll(PDO::FETCH_ASSOC);

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
{
Expand Down

0 comments on commit b1c49a9

Please sign in to comment.