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

Partially fix transaction autocommit and fix compatibility fatal error #39

Closed czachor closed 4 years ago

czachor commented 4 years ago

1.

Some databases, including MySQL, automatically issue an implicit COMMIT when a database definition language (DDL) statement such as DROP TABLE or CREATE TABLE is issued within a transaction. The implicit COMMIT will prevent you from rolling back any other changes within the transaction boundary.

Source: https://www.php.net/manual/en/pdo.begintransaction.php

I've created a new method which checks if logs table exists, called in most cases only once. If the table exists, query CREATE TABLE... isn't called preventing transaction autocommit.

Todo: solution to prevent autocommit if table doesn't exist - first call of method createLogsTable() (when the table doesn't exist) still breaks transaction. See #25

  1. Fix for: Fatal error: Declaration of MySQLHandler\MySQLHandler::write(array $record) must be compatible with Monolog\Handler\AbstractProcessingHandler::write(array $record): void in [...]\vendor\wazaari\monolog-mysql\src\MySQLHandler\MySQLHandler.php on line 164
cr-lgl commented 4 years ago

I think it's better to handle a query with a flag than to run it. Also, I think this was solved by #42.