quikk has asked for the wisdom of the Perl Monks concerning the following question:

Hello.

I'm brand new to perl, and I'd like to request some help on a topic that has puzzled me:

According to CPAN, "1.19_10 M(y)sqlPerl is no longer a separate module. Instead it is emulated using the DBI drivers."

If I've got tons of code that uses use Mysql;, and a little code that uses a custom sql wrapper for DBI, use CUSTOM::SQL;. I need to convert all instances of "Mysql" database connectivity to the custom wrapper, but I believe "use Mysql;" uses different functions than "use DBI;", such as:

@arr = $sth->fetchrow; vs. @row_ary  = $sth->fetchrow_array;,

$dbh = Mysql->connect($host, $database, $user, $password); vs. CUSTOM::SQL::connect();, and so on.

My question: Should I just do "find/replace" on all of the Mysql-particular functions for the DBI-particular functions? Or is there some set of functions applicable to both modules?

If anyone could point me to a reference that might help with Mysql module to DBI module conversion, I'd be ecstatic, as I've searched high and low.

Replies are listed 'Best First'.
Re: use Mysql; vs. use DBI;
by thomas895 (Deacon) on May 19, 2012 at 19:55 UTC

    From what it looks like, they are compatible. However, in the future, make sure to use DBD::mysql and not Mysql anymore. Eventually, it will be completely deprecated, and it Mysql.pm is therefore not a good idea to use it anymore.

    * Slightly clarified one part.
    ~Thomas~ I believe that the source code to life is written in Perl :-)

      Programming in Perl, and then not using DBI for your database stuff, is like buying a sports car and getting a horse to pull it along.

      perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

      Exactly where in the docs for DBD::mysql did you read that you should use DBD::mysql? Everytime I've read it, it told me to use DBI.

        It was implied that you actually use DBI. Unless you want to add DBD::mysql as well, if you really want to.
        But you're missing the point of my post. The OP was asking about whether Mysql.pm or DBI.pm is better. I said that DBD::mysql was the better option, and anyone who has just skimmed the DBI documentation knows that the drivers reside in the DBD::* modules.

        ~Thomas~
        I believe that the source code to life is written in Perl :-)