Closed TwinMist closed 1 year ago
Hello,
```
$pdo = new \PDO('mysql:host=localhost;dbname=monolog', 'monolog', 'monolog');
$mysqlHandler = new \MySQLHandler\MySQLHandler($pdo, "log", array('channel', 'CORRELATION', 'errorFile', 'errorFile', 'errorLine', 'errorTrace'), \Monolog\Logger::INFO);
$logger->pushHandler($mysqlHandler);
$content = [
'test1' => 'aaa',
'test2' => 'bbb'
];
$logger->error('Test', $content);
---------------------------
When i debug the script i find the query for mysql.
Query: INSERT INTO `log` (channel, level, message, time, channel, CORRELATION, errorFile, errorFile, errorLine, errorTrace) VALUES (:channel, :level, :message, :time, :channel, :CORRELATION, :errorFile, :errorFile, :errorLine, :errorTrace)
What is wrong ?
Your sincerly
Stephan
@TwinMist @StephanKrauss I think I'll have time to check this out next week, please wait a little while.
Reverting commit 45a4bf3168c21b13272d16651f073a62bffd3cb0 fixes this for me.
For once, the check for unused keys is using a wrong array index:
https://github.com/waza-ari/monolog-mysql/blob/45a4bf3168c21b13272d16651f073a62bffd3cb0/src/MySQLHandler/MySQLHandler.php#L210
This should probably be if(! isset($contentArray[$context]))
.
But the check does not seem to work correctly anyway as the insert statement is build and prepared prior to the unused keys getting removed. Thus, the statement always contains all additional fields/keys.
By (trying to) remove them after the statement has already been prepared, the parameters won't match up.
I've addressed this issue in https://github.com/waza-ari/monolog-mysql/pull/47/commits/4eb4ad35a16ecf5e16701326fb6a419bedee4552. It will be resolved in the upcomming release v2.
Hi Just had to revert back to 1.0.4 because in 1.0.5 was getting PHP Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in
any ideas