Issues

ZF2-531: Zend log to Db writer and MySQL

Description

The error message I get: Object of class DateTime could not be converted to string in /Zend/Db/Adapter/Driver/Pdo/Statement.php on line 256

The MySQL table I have: CREATE TABLE logs ( date datetime DEFAULT NULL, type tinyint default NULL, event varchar(255) default NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

The code:

<?php

use Zend\Log; use Zend\Db\Adapter\Adapter as DbAdapter;

$showDebug = true; $logDebug = true;

$logger = new Log\Logger;

// add DB writer $dbConfig = array( 'driver' => 'Pdo', 'dsn' => 'mysql:dbname=logs;hostname=localhost', 'username' => 'root', 'password' => 'password', 'driver_options' => array( PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\'' ), ); $mapping = array( 'timestamp' => 'date', 'priority' => 'type', 'message' => 'event' ); $db = new DbAdapter($dbConfig); $dbWriter = new Log\Writer\Db($db, 'logs', $mapping); $logPriority = $logDebug ? Log\Logger::DEBUG : Log\Logger::INFO; $dbWriter->addFilter(new Log\Filter\Priority($logPriority)); $logger->addWriter($dbWriter);

// do the logging $logger->crit('Crit message goes here!');

Comments

Apologies guys. Still had ZF2 beta2 on this desktop. Updated to 2.0.0 and don’t have this problem any more. ZF2 is just great!

Was not a bug. I was using the wrong Zend Framework version (beta2) on this desktop.