monolog-mysql icon indicating copy to clipboard operation
monolog-mysql copied to clipboard

PDOStatement::execute(): SQLSTATE[HY093]

Open TwinMist opened this issue 4 years ago • 3 comments

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

TwinMist avatar Apr 27 '20 12:04 TwinMist

Hello,

i have the same problem. Here is my test setup

      ```

$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

StephanKrauss avatar May 27 '20 11:05 StephanKrauss

@TwinMist @StephanKrauss I think I'll have time to check this out next week, please wait a little while.

cr-lgl avatar May 28 '20 04:05 cr-lgl

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.

nox-4O4 avatar Jun 15 '20 23:06 nox-4O4

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.

amacado avatar Sep 18 '23 22:09 amacado