#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Location
    Chelyabinsk, Russia
    Posts
    3
    Rep Power
    0
    Hi all!

    Could anyone show me how may I connect from perl to mysql. Simple a piece of code will be enough. Thank you.

    ------------------
    ___
    Tim
  2. #2
  3. No Profile Picture
    RyanP
    Guest
    Devshed Newbie (0 - 499 posts)
    hehe, there's a little more to it than that

    do you have DBI and DBD:mysql installed?

    if so, check out the DBI documentation that came with your source to find examples of using the module

    your code will look something like this
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>use DBI;

    $dbh = DBI->connect('DBI:mysql:dbName')
    or die "Couldn't connect to database: " . DBI->errstr;
    $sth = $dbh->prepare('SELECT * FROM tableName')
    or die "Couldn't prepare statement: " . $dbh->errstr;
    $sth->execute()
    or die "Couldn't execute statement: " . $sth->errstr;
    while (@data = $sth->fetchrow_array())
    {
    $field1 = $data[0];
    $field2 = $data[1];
    }
    $sth->finish;
    $dbh->disconnect;[/code]

    [This message has been edited by RyanP (edited September 02, 2000).]
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Location
    Chelyabinsk, Russia
    Posts
    3
    Rep Power
    0
    Thank's for explanations.
    I found DBI module at www.perl.com/CPAN-local/modules/by-module/ but not found DBD:mysql. Where I can find it? Do you know?

    ------------------
    ___
    Tim
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Aug 2000
    Location
    Indiana
    Posts
    614
    Rep Power
    15
    Don't worry about DBD:mysql. DBI is all you need.
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Location
    Chelyabinsk, Russia
    Posts
    3
    Rep Power
    0
    One more problem .

    I'm on WinNT. I unpacked the DBI archive, if I simple copy DBI.pm into perl/lib directory apache rase the error on "use DBI" line in CGI script.

    Can't find loadable module for DBI.pm line...

    Shall I first build anything how indexed in readme file? Other instruction I found say that it doesn't nessesary on WinNT.
    Thouth I tryed to build it. Command: "perl Makefile.PL" passed and create "makefile." file, but commnad: "make" rase an error.

    Did you install this module on WinNT or do you know anyone who did it? May be there is a ready to use DBI.pm module for WinNT?

    I'm in misunderstandings.

    ------------------
    ___
    Tim
  10. #6
  11. No Profile Picture
    RyanP
    Guest
    Devshed Newbie (0 - 499 posts)
    are you using ActivePerl? if so, then you should probably use their /bin/ppm to automatically download and install DBI

IMN logo majestic logo threadwatch logo seochat tools logo