Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
      What are the benefits of using one of the DB modules like DBI as opposed to just making a mysql connection like this.

Are you kidding me? There's a whole ton of work you save yourself using DBI and the associated driver modules in the DBD:: family. I'm not even sure how your code shown in your post would even accomplish anything.

One typical example of code:

#!/usr/bin/perl -w use strict; use DBI; # connect to the database and create a handle to the connection. my $dbh=DBI->connect('DBI:mysql:host=myhost.domain.tld;database=mydata +base', 'user','password') or die $DBI::errstr; #create a statement handle and prep our SQL my $sth=$dbh->prepare(qq( select user_id,username,password,given,surname from users_table order +by user_id )) or die $dbh->errstr; $sth->execute(); while (my $row=$sth->fetchrow_arrayref){ # do something with it } | rest of code
In my mind and I'm sure I'm not alone using DBI is just basic to using databases with Perl. I am positive that without using DBI and writing code to scrape the output from a database the way you seem to describe would require a lot more code that my example above. You'd also run into lots of issues with syntax, quoting and other issues that might be difficult to track down and diagnose.

That reminds me: there's also the issue of portability. In 99% of the cases where I've written code that performs database operations I've been able to port it between database engines merely by switching which DBD driver I use. On rare occasion (using stored procedures for instance) I've had to change something up but that's rare.


Peter L. Berghold -- Unix Professional
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg

In reply to Re: What use DBI? by blue_cowdawg
in thread What use DBI? by monk2b

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others chanting in the Monastery: (7)
    As of 2014-09-19 06:09 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      How do you remember the number of days in each month?











      Results (131 votes), past polls