Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Tricks with DBI

by btrott (Parson)
on Apr 14, 2000 at 03:36 UTC ( #7568=perltutorial: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download

  1. or download this
        my $dbh = DBI->connect('foo', 'bar', 'baz', 'mysql')
            or die "Can't connect: ", $DBI::errstr;
        $dbh->{RaiseError} = 1;
  2. or download this
        my $sth = $dbh->prepare("select id from foo")
            or die "Can't prepare: ", $dbh->errstr;
            or die "Can't execute: ", $dbh->errstr;
  3. or download this
        select id, name, phone from people
  4. or download this
        my($id, $name, $phone);
        $sth->bind_columns(undef, \$id, \$name, \$phone);
  5. or download this
        while ($sth->fetch) {
            print join("\t", $id, $name, $phone), "\n";
  6. or download this
        # Connect to the database and set the RaiseError
        # attribute so that any database error will
  7. or download this
        use Apache::DBI;
  8. or download this
        use DBI;

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perltutorial [id://7568]
[james28909]: i figured out a neet trick
[Lady_Aleena]: james28909, what neat trick?
[james28909]: now if i have packed a script into a PDK exe, and misplaced the source, i can print it.
[james28909]: but you have to prepare for it first by adding this to the source
[james28909]: seek DATA, 0, 0; while (<DATA>) { print; }
[Lady_Aleena]: Sounds interesting. Have you written a meditation or cool use for it?
[Lady_Aleena]: It might be something PerlMonks at large would be interested in.

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2017-05-01 00:06 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (543 votes). Check out past polls.