tuupola / dbal-psr3-logger

PSR-3 Logger for Doctrine DBAL
MIT License
3 stars 1 forks source link

Fatal Error when a parameter is a DateTime object #1

Open eduardoweiland opened 6 years ago

eduardoweiland commented 6 years ago

Catchable Fatal Error: Object of class DateTime could not be converted to string (uncaught exception) at /var/www/vendor/tuupola/dbal-psr3-logger/src/Psr3Logger.php line 40

tuupola commented 6 years ago

Can you show minimal code which causes this error?

eduardoweiland commented 6 years ago

Sure. I am using Silex with Doctrine ORM, but I can reproduce this error with just Doctrine DBAL:

<?php

use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Types\Type;
use Monolog\Logger;
use Monolog\Handler\NullHandler;
use Tuupola\DBAL\Logging\Psr3Logger;

require './vendor/autoload.php';

$config = new Configuration();

$connectionParams = array(
    'url' => 'mysql://root:root@127.0.0.1/test',
);

$conn = DriverManager::getConnection($connectionParams, $config);

$logger = new Logger('name');
$logger->pushHandler(new NullHandler());

$sqlLogger = new Psr3Logger($logger);
$config->setSQLLogger($sqlLogger);

$sql = "INSERT INTO records (id, creation_date) VALUES (?, ?)";
$stmt = $conn->prepare($sql);
$stmt->bindValue(1, 42);
$stmt->bindValue(2, new \DateTime(), Type::DATETIME);
$stmt->execute();

And this is the database:

CREATE DATABASE test;
USE test;
CREATE TABLE records (id INT, creation_date DATETIME, PRIMARY KEY(id));

Running this with php test.php gives the error:

PHP Recoverable fatal error: Object of class DateTime could not be converted to string in /var/www/vendor/tuupola/dbal-psr3-logger/src/Psr3Logger.php on line 40

tuupola commented 6 years ago

Thanks! Now I can easily make test for it.

eduardoweiland commented 6 years ago

Any update on this?