monolog-mysql icon indicating copy to clipboard operation
monolog-mysql copied to clipboard

Removed unsetting of null values of $contentArray

Open frugan-dev opened this issue 5 years ago • 1 comments

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

frugan-dev avatar Jul 09 '19 13:07 frugan-dev

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

cr-lgl avatar Jul 02 '20 09:07 cr-lgl

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

amacado avatar Sep 17 '23 22:09 amacado

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.

amacado avatar Sep 18 '23 22:09 amacado