in reply to DBI do vs prepare

BrianC,

There is no hard and fast rule about just how well the prepare, execute, execute ... and the do variations will work. Generally speaking the $dbh->do( ... ) will create and destroy a new statement handle for each use. Using the $dbh->prepare( .. ) will almost inevitably result in better performance, particularly on databases which do actually cache the statement. Sadly, I don't think mysql does. At least prior to MySQL 4.1.3 it did not cache prepared statements, more recently you can enable the caching of prepares by enabling the mysql_server_prepare option. This is a connection option and is detailed in the latest DBD::mysql documentation ( 3.0006 as I write this ). That being said, their is also the issue of placeholders you raised, DBD::mysql emaulates placeholders because I understand they are not directly supported by the MySQL API. In carefully crafted code there can be an advantage with MySQL, but not as great as with Oracle, for example.

jdtoronto

Replies are listed 'Best First'.
Re^2: DBI do vs prepare
by BrianC (Acolyte) on Aug 15, 2006 at 15:21 UTC
    jdtoronto,

    I added the connection option, but there was no change in performance. I think the problem is with the lack of support for placeholders.

    Thanks,

    Brian