waza-ari / monolog-mysql

MySQL Handler for Monolog, which allows to store log messages to a MySQL Table
MIT License
141 stars 85 forks source link

Removed unsetting of null values of $contentArray #31

Closed frugan-dev closed 1 year ago

frugan-dev commented 5 years ago

Because however later they are added again with array_combine().

test.php file:

<?php

use MySQLHandler\MySQLHandler;

require __DIR__ . '/vendor/autoload.php';

putenv('DB_HOST=localhost');
putenv('DB_NAME=database');
putenv('DB_USER=user');
putenv('DB_PASS=password');

$conn = new PDO('mysql:host='.getenv('DB_HOST').';dbname='.getenv('DB_NAME'), getenv('DB_USER'), getenv('DB_PASS'));

$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$mySQLHandler = new MySQLHandler($conn, 'log', ['username', 'userid'], \Monolog\Logger::DEBUG);

$logger = new \Monolog\Logger( 'debug' );
$logger->pushHandler( $mySQLHandler );

$logger->addWarning('This is a great message, woohoo!', ['username'  => 'John Doe', 'userid'  => null]);

Command:

$ php -f test.php

Output:

PHP Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in .../monolog-mysql/vendor/wazaari/monolog-mysql/src/MySQLHandler/MySQLHandler.php:214

cr-lgl commented 4 years ago

I tried running your example, but the situation is not reproducible, can you explain more?

amacado commented 1 year ago

Hello @frugan-it, I'll take a look into this and take it into consideration for the next release.

amacado commented 1 year ago

I've refactored the process in https://github.com/waza-ari/monolog-mysql/pull/47/commits/4eb4ad35a16ecf5e16701326fb6a419bedee4552 which should resolve this issue. Feel free to re-open the pull request if you want to point any additional problems.