Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9250355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:25:39+00:00 2026-06-18T10:25:39+00:00

I want to save log entries to my MySQL database from Zend Framework 2.

  • 0

I want to save log entries to my MySQL database from Zend Framework 2. I am using Zend\Log\Logger with a Zend\Log\Writer\Db writer. By supplying the writer with an array, one can choose which columns to save what data to (e.g. timestamp into a “log_date” column) and which data to save. Here is what I am doing:

$logger = new Zend\Log\Logger();

$mapping = array(
    'timestamp' => 'timestamp_column',
    'priority'  => 'priority_column',
    'message'   => 'message_column',
    'extra' => 'extra_column'
);

$logger->addWriter(new Zend\Log\Writer\Db($dbAdapter, 'table_name', $mapping));
$logger->err('some message', array('some extra information'));

The problem I am facing is that the array of column names and their values contain an incorrect column name for the “extra” column. Based on the array above, it should be inserting the value “some extra information” into the “extra_column” column. The problem is that the Zend\Log\Writer\Db class is using the letter “e” as the name of the extra column. This comes from the first letter of “extra_column” in my array above. For some reason, it is taking the first letter of “extra_column” and using it as the column name instead of the entire value.

I took a look at the source code. The mapEventIntoColumn method is being used to get the column names and values as an array. I copied in the relevant part of the method below.

// Example:
// $event = array('extra' => array(0 => 'some extra information'));
// $columnMap = array('extra' => 'extra_column');
// Return: array('e' => 'some extra information')
// Expected (without looking at the code below): array('extra_column' => 'some extra information')
protected function mapEventIntoColumn(array $event, array $columnMap = null) {
    $data = array();
    foreach ($event as $name => $value) {
        if (is_array($value)) {
            foreach ($value as $key => $subvalue) {
                if (isset($columnMap[$name][$key])) {
                    $data[$columnMap[$name][$key]] = $subvalue;
                }
            }
        }
    }
    return $data;
}

The $event parameter is an array containing the same keys as my $mapping array in my first code snippet and the values for the log message. The $columnMap parameter is the $mapping array from my first code snippet (array values are column names).

What actually seems to happen is that because I am passing in extra information as an array (this is required), the inner foreach loop is executed. Here, $key is 0 (the index) so it is actually doing like this: $columnMap['extra'][0]. This gives the letter “e” (the first letter in “extra_column”), which is used as the column name, where it should be the entire column name instead.

I tried to supply my own key in the extra array when calling the log method, but the same happens. The official documentation shows no examples of usage of the extra parameter. I want to insert information that can help me debug errors into my table, so I would like to use it.

Is this a bug or am I missing something? It seems really strange to me! I hope I explained it well enough – it is quite tricky!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T10:25:40+00:00Added an answer on June 18, 2026 at 10:25 am

    Since Daniel M has not yet posted his comment as an answer, I will refer you to his comment which solved the problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My requirement is i want to save some data in database by using web-services.
I want to save to a log file some SQL query rails performs, (namely
I am working on a project and I want to save the user log
I want to save and load my xml data using XmlReader. But I don't
I want to save and add on every click data to an array. I
Can i save my app's log when its not connect with Eclipse using USB?
If i want to save information/log when some event accour in a SISS package,
I want to save my currently database on localhost to file. I am trying
I want to save some ~35000 objects in my IndexedDB's objectstore. I am using
I want to parse logfiles from rackspace. I'm using the official python sdk .

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.