Issues

ZF2-562: Zend\Log\Write\Db creates non-existing database table columns

Description

Zend\Log\Writer\Db::eventIntoColumn creates new non-existing database table columns when $value is an array.


protected function eventIntoColumn(array $event)
{
    if (empty($event)) {
        return array();
    }

    $data = array();
    foreach ($event as $name => $value) {
        if (is_array($value)) {
            foreach ($value as $key => $subvalue) {
                // New database table columns are being created here...
                $data[$name . $this->separator . $key] = $subvalue;
            }
        } else {
            $data[$name] = $value;
        }
    }
    return $data;
}

This is highly illogical, because now this PHP-script decides what database table columns should exist. When an array with other keys is used all of a sudden the script generates new, other database columns and eventually make the entire script fail again because of a database error due to non-existing columns. The user should define the columns to be used and the script should never add non-existing database tabel columns on its own.

More logical would be to define a way to handle arrays with something like json_encode() or serialize(). The most important thing is that it does not break the logging like it does now, so when $value is an array it must always return a string, because that is the only type of variable you can write to a database table column.

Comments

This issue has been closed on Jira and moved to GitHub for issue tracking. To continue following the resolution of this issues, please visit: https://github.com/zendframework/zf2/issues/2588