Laravel complains about query with duplicate named parameters

后端 未结 2 1551
走了就别回头了
走了就别回头了 2020-12-20 09:54

When I do (in laravel):

 1,
]);

It says:

2条回答
  •  失恋的感觉
    2020-12-20 10:26

    From what I can see it all comes down to mysql being unable to deal with named parameters.

    mysqli::prepare:

    This parameter can include one or more parameter markers in the SQL statement by embedding question mark (?) characters at the appropriate positions.

    pdo::prepare:

    You must include a unique parameter marker for each value you wish to pass in to the statement when you call PDOStatement::execute(). You cannot use a named parameter marker of the same name more than once in a prepared statement, unless emulation mode is on.

    Laravel has emulation mode disabled by default. One can enable it in config/database.php by adding 'options' => [PDO::ATTR_EMULATE_PREPARES => TRUE] to connection settings. That way you will get the same result as in pure php. Not sure that's a good idea, though.

提交回复
热议问题