catfan / Medoo

The lightweight PHP database framework to accelerate the development.
https://medoo.in
MIT License
4.84k stars 1.15k forks source link

Cannot unset string offsets error from get() with $where as string. #957

Closed juejixiaohaipi closed 3 years ago

juejixiaohaipi commented 3 years ago

Describe the bug A clear and concise description of what the bug is.

Information

Detail Code The detail code causes the problem.

Expected output A clear and concise description of what output you expected.

juejixiaohaipi commented 3 years ago

public function get($table, $join = null, $columns = null, $where = null) { $map = []; $result = []; $column_map = []; $current_stack = [];

    if ($where === null)
    {
        $column = $join;
        unset($columns[ 'LIMIT' ]);
    }
    else
    {
        $column = $columns;
        unset($where[ 'LIMIT' ]);
    }

    $is_single = (is_string($column) && $column !== '*');

    $query = $this->exec($this->selectContext($table, $map, $join, $columns, $where) . ' LIMIT 1', $map);

    if (!$this->statement)
    {
        return false;
    }

    $data = $query->fetchAll(PDO::FETCH_ASSOC);

    if (isset($data[ 0 ]))
    {
        if ($column === '*')
        {
            return $data[ 0 ];
        }

        $this->columnMap($columns, $column_map, true);

        $this->dataMap($data[ 0 ], $columns, $column_map, $current_stack, true, $result);

        if ($is_single)
        {
            return $result[ 0 ][ $column_map[ $column ][ 0 ] ];
        }

        return $result[ 0 ];
    }
}

public function get($table, $join = null, $columns = null, $where = null) { $map = []; $result = []; $column_map = []; $current_stack = [];

    if ($where === null)
    {
        $column = $join;
        unset($columns[ 'LIMIT' ]);
    }
    else
    {
        $column = $columns;
        unset($where[ 'LIMIT' ]);
    }

    $is_single = (is_string($column) && $column !== '*');

    $query = $this->exec($this->selectContext($table, $map, $join, $columns, $where) . ' LIMIT 1', $map);

    if (!$this->statement)
    {
        return false;
    }

    $data = $query->fetchAll(PDO::FETCH_ASSOC);

    if (isset($data[ 0 ]))
    {
        if ($column === '*')
        {
            return $data[ 0 ];
        }

        $this->columnMap($columns, $column_map, true);

        $this->dataMap($data[ 0 ], $columns, $column_map, $current_stack, true, $result);

        if ($is_single)
        {
            return $result[ 0 ][ $column_map[ $column ][ 0 ] ];
        }

        return $result[ 0 ];
    }
}
juejixiaohaipi commented 3 years ago

fot the function get,the row unset($columns[ 'LIMIT' ]);may bring error.if there none limit

juejixiaohaipi commented 3 years ago

at the row 1599

juejixiaohaipi commented 3 years ago

this is my code to use the function getget("article",['content'],"where domain='js-version' and is_del =0");

catfan commented 3 years ago

The $where parameter should be array not string.

Please read the document https://medoo.in/api/get.

juejixiaohaipi commented 3 years ago

ok,thank you.i used the very old version.