I'm trying to writes PHP error to a mysql database. If there’s a way we can change it so that instead of writing directly to an error_log file, it sends the error to a script, which records it in the db.
How about using a framework for logging. Log4PHP would also improve your logging over all. It has a MySQL appender. https://logging.apache.org/log4php/docs/appenders/pdo.html