PDO MySQL: Use PDO::ATTR_EMULATE_PREPARES or not?

前端 未结 7 2051
南笙
南笙 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:57

    I'd recommend enabling real database PREPARE calls as the emulation doesn't catch everything.., for example, it will prepare INSERT;!

    var_dump($dbh->prepare('INSERT;'));
    $dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
    var_dump($dbh->prepare('INSERT;'));
    

    The output

    object(PDOStatement)#2 (1) {
      ["queryString"]=>
      string(7) "INSERT;"
    }
    bool(false)
    

    I'll gladly take a performance hit for code that actually works.

    FWIW

    PHP Version: PHP 5.4.9-4ubuntu2.4 (cli)

    MySQL Version: 5.5.34-0ubuntu0

提交回复
热议问题