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

Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens #23

Closed myleshk closed 5 years ago

myleshk commented 7 years ago

Error message:

Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in **/vendor/wazaari/monolog-mysql/src/MySQLHandler/MySQLHandler.php on line 214

Situation:

When some additionalFields are provided with empty values. No logs are recorded to database when this warning shows.

Code problem observed:

While $contentArray contains the full list of key-values, $this->statement is only prepared with keys that has non-empty values. Thus it is true that number of bound variables does not match number of tokens.

darkoromanov commented 7 years ago

I've added this code at line 208:

//Remove unused keys
foreach($this->additionalFields as $key => $context) {
    if(! isset($contentArray[$key]))
        unset($this->additionalFields[$key]);
}
cr-lgl commented 5 years ago

Fixed #23