PDO MySQL: Use PDO::ATTR_EMULATE_PREPARES or not?

前端 未结 7 2044
南笙
南笙 2020-11-22 11:23

This is what I\'ve read so far about PDO::ATTR_EMULATE_PREPARES:

  1. PDO\'s prepare emulation is better for performance since MySQL\'s native prepare bypasses the
7条回答
  •  不要未来只要你来
    2020-11-22 11:51

    Why switch emulation to ‘false’?

    The main reason for this is that having the database engine do the prepare instead of PDO is that the query and the actual data are sent separately, which increases security. This means when the parameters are passed to the query, attempts to inject SQL into them are blocked, since MySQL prepared statements are limited to a single query. That means that a true prepared statement would fail when passed a second query in a parameter.

    The main argument against using the database engine for the prepare vs PDO is the two trips to the server – one for the prepare, and another for the parameters to get passed – but I think the added security is worth it. Also, at least in the case of MySQL, query caching has not been an issue since version 5.1.

    https://tech.michaelseiler.net/2016/07/04/dont-emulate-prepared-statements-pdo-mysql/

提交回复
热议问题