in reply to How can I make DBI's prepare() fail? [MySQL]

Either you just replace the method with a failing method:

{ local *DBI::db::prepare = sub { die "In prepare" }; dies_ok my_framework_connect(); }

... or you use a different database driver. DBD::mysql doesn't do anything in ->prepare, but other database drivers may compile the statement then and there.

Replies are listed 'Best First'.
Re^2: How can I make DBI's prepare() fail? [MySQL]
by Cody Fendant (Hermit) on Dec 23, 2018 at 10:07 UTC
    DBD::mysql doesn't do anything in ->prepare

    Wait, what? Why am I doing prepare(), then execute()? Just so I can have parameterised queries?

      You're following ->prepare, ->execute because that's how the DBI API is designed. A DBD is free to do as much or as little work in any of the two steps. I think DBD::mysql merely stores the SQL string in ->prepare and does all the checking etc. in ->execute. You can switch to just using ->selectall_arrayref, but that way you lose easy access to caching. Also, should you ever switch to a different database, it might do more work during ->prepare and thus that phase might raise errors.