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

"PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number" when used with Silex and Monolog Service Provider #12

Closed Kwbmm closed 7 years ago

Kwbmm commented 8 years ago

I'm trying to integrate monolog-mysql with MonologServiceProvider of Silex. I followed the guide for pushing this handler into Monolog Service Provider, but as I call a Silex route, I get:

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

    Notice: Array to string conversion in <myPath>/vendor/wazaari/monolog-mysql/src/MySQLHandler/MySQLHandler.php on line 131

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

    Notice: Array to string conversion in <myPath>/vendor/wazaari/monolog-mysql/src/MySQLHandler/MySQLHandler.php on line 131

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

    Notice: Array to string conversion in <myPath>/vendor/wazaari/monolog-mysql/src/MySQLHandler/MySQLHandler.php on line 131

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

    Notice: Array to string conversion in <myPath>/vendor/wazaari/monolog-mysql/src/MySQLHandler/MySQLHandler.php on line 131

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

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

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

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

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

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

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

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

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

MonologServiceProvider and monolog-mysql are registered this way:

    $app->register(new Silex\Provider\MonologServiceProvider(), array(
        'monolog.logfile' => __DIR__.'/logs/myApp.log',
        'monolog.name' => 'myApp'
    ));
    /**
     * Add the MySQL handler.
     * See: https://github.com/waza-ari/monolog-mysql
     */
    $app->extend('monolog', function($monolog,$app){
        //Create MysqlHandler
        $dbInstance = new PDO('mysql:host=localhost;dbname=myApp', 'root', '');
        $mySQLHandler = new MySQLHandler\MySQLHandler($dbInstance, "logs", array('type'), \Monolog\Logger::DEBUG);
        $monolog->pushHandler($mySQLHandler);
        return $monolog;
    });

The service provider is somewhat working because it logged something:

    [2016-05-17 19:16:22] myApp.INFO: Monolog service Registered {"logText":"Monolog service Registered","timeRecord":1463505382,"type":"0"} []
    [2016-05-17 19:16:22] myApp.INFO: Matched route "GET_". {"route_parameters":{"_controller":"[object] (Closure: {})","_route":"GET_"},"request_uri":"http://localhost/"} []
    [2016-05-17 19:16:22] myApp.INFO: > GET / [] []
    [2016-05-17 19:16:22] myApp.INFO: < 200 [] []
    [2016-05-17 19:16:23] myApp.INFO: Monolog service Registered {"logText":"Monolog service Registered","timeRecord":1463505383,"type":"0"} []
    [2016-05-17 19:16:23] myApp.INFO: Matched route "GET_". {"route_parameters":{"_controller":"[object] (Closure: {})","_route":"GET_"},"request_uri":"http://localhost/"} []
    [2016-05-17 19:16:23] myApp.INFO: > GET / [] []
    [2016-05-17 19:16:23] myApp.INFO: < 200 [] []
    [2016-05-17 19:18:36] myApp.INFO: Monolog service Registered [] []
    [2016-05-17 19:18:36] myApp.INFO: Matched route "GET_". {"route_parameters":{"_controller":"[object] (Closure: {})","_route":"GET_"},"request_uri":"http://localhost/"} []
    [2016-05-17 19:18:36] myApp.INFO: > GET / [] []
    [2016-05-17 19:18:36] myApp.INFO: < 200 [] []
    [2016-05-17 19:18:36] myApp.INFO: Monolog service Registered [] []
    [2016-05-17 19:18:36] myApp.INFO: Matched route "GET_". {"route_parameters":{"_controller":"[object] (Closure: {})","_route":"GET_"},"request_uri":"http://localhost/"} []
    [2016-05-17 19:18:36] myApp.INFO: > GET / [] []
    [2016-05-17 19:18:36] myApp.INFO: < 200 [] []
    [2016-05-17 19:21:29] myApp.INFO: Monolog service Registered [] []
    [2016-05-17 19:21:29] myApp.INFO: Matched route "GET_". {"route_parameters":{"_controller":"[object] (Closure: {})","_route":"GET_"},"request_uri":"http://localhost/"} []
    [2016-05-17 19:21:29] myApp.INFO: > GET / [] []
    [2016-05-17 19:21:29] myApp.INFO: < 200 [] []
    [2016-05-17 19:22:36] myApp.INFO: Monolog service Registered [] []
    [2016-05-17 19:22:36] myApp.INFO: Matched route "GET_". {"route_parameters":{"_controller":"[object] (Closure: {})","_route":"GET_"},"request_uri":"http://localhost/"} []
    [2016-05-17 19:22:36] myApp.INFO: > GET / [] []
    [2016-05-17 19:22:36] myApp.INFO: < 200 [] []
    [2016-05-17 19:23:17] myApp.INFO: Monolog service Registered [] []
    [2016-05-17 19:23:17] myApp.INFO: Matched route "GET_". {"route_parameters":{"_controller":"[object] (Closure: {})","_route":"GET_"},"request_uri":"http://localhost/"} []
    [2016-05-17 19:23:17] myApp.INFO: > GET / [] []
    [2016-05-17 19:23:17] myApp.INFO: < 200 [] []
    [2016-05-17 19:24:45] myApp.INFO: Monolog service Registered [] []
    [2016-05-17 19:24:45] myApp.INFO: Matched route "GET_". {"route_parameters":{"_controller":"[object] (Closure: {})","_route":"GET_"},"request_uri":"http://localhost/"} []
    [2016-05-17 19:24:45] myApp.INFO: > GET / [] []
    [2016-05-17 19:24:45] myApp.INFO: < 200 [] []
    [2016-05-17 19:27:01] myApp.INFO: Monolog service Registered [] []
    [2016-05-17 19:27:01] myApp.INFO: Matched route "GET_". {"route_parameters":{"_controller":"[object] (Closure: {})","_route":"GET_"},"request_uri":"http://localhost/"} []
    [2016-05-17 19:27:01] myApp.INFO: > GET / [] []
    [2016-05-17 19:27:01] myApp.INFO: < 200 [] []
    [2016-05-17 19:28:10] myApp.INFO: Monolog service Registered [] []
    [2016-05-17 19:28:10] myApp.INFO: Matched route "GET_". {"route_parameters":{"_controller":"[object] (Closure: {})","_route":"GET_"},"request_uri":"http://localhost/"} []
    [2016-05-17 19:28:10] myApp.INFO: > GET / [] []
    [2016-05-17 19:28:10] myApp.INFO: < 200 [] []
    [2016-05-17 19:28:11] myApp.INFO: Monolog service Registered [] []
    [2016-05-17 19:28:11] myApp.INFO: Matched route "GET_". {"route_parameters":{"_controller":"[object] (Closure: {})","_route":"GET_"},"request_uri":"http://localhost/"} []
    [2016-05-17 19:28:11] myApp.INFO: > GET / [] []
    [2016-05-17 19:28:11] myApp.INFO: < 200 [] []
    [2016-05-17 19:30:43] myApp.INFO: Monolog service Registered [] []
    [2016-05-17 19:30:43] myApp.INFO: Matched route "GET_". {"route_parameters":{"_controller":"[object] (Closure: {})","_route":"GET_"},"request_uri":"http://localhost/"} []
    [2016-05-17 19:30:43] myApp.INFO: > GET / [] []
    [2016-05-17 19:30:43] myApp.INFO: < 200 [] []
    [2016-05-17 19:30:44] myApp.INFO: Monolog service Registered [] []
    [2016-05-17 19:30:44] myApp.INFO: Matched route "GET_". {"route_parameters":{"_controller":"[object] (Closure: {})","_route":"GET_"},"request_uri":"http://localhost/"} []
    [2016-05-17 19:30:44] myApp.INFO: > GET / [] []
    [2016-05-17 19:30:44] myApp.INFO: < 200 [] []
    [2016-05-17 19:32:55] myApp.INFO: Monolog service Registered [] []
    [2016-05-17 19:32:55] myApp.INFO: Matched route "GET_". {"route_parameters":{"_controller":"[object] (Closure: {})","_route":"GET_"},"request_uri":"http://localhost/"} []
    [2016-05-17 19:32:55] myApp.INFO: > GET / [] []
    [2016-05-17 19:32:55] myApp.INFO: < 200 [] []
    [2016-05-17 19:32:56] myApp.INFO: Monolog service Registered [] []
    [2016-05-17 19:32:56] myApp.INFO: Matched route "GET_". {"route_parameters":{"_controller":"[object] (Closure: {})","_route":"GET_"},"request_uri":"http://localhost/"} []
    [2016-05-17 19:32:56] myApp.INFO: > GET / [] []
    [2016-05-17 19:32:56] myApp.INFO: < 200 [] []

What am I doing wrong? Is this plugin compatible with Silex+Monolog Service Provider?

waza-ari commented 7 years ago

Hm... I am not familiar with Silex or their Monolog Service Provider at all, I cannot really help you with that. As the issue is quite old: did you manage to solve this or did you give up? If you still need help, could you please try again with the most current version (1.0.4) and post the Warnings again?

Without knowing the details of Silex or the provider, I'd say there is nothing wrong with the way you are trying to integrate that.

Kwbmm commented 7 years ago

As the issue is quite old: did you manage to solve this or did you give up?

I gave up because I had no knowledge on how the Silex extension system was working and had no time to experiment with it.