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

    Join Date
    Apr 2000
    Posts
    6
    Rep Power
    0
    How can i connect PERL with MySQL
  2. #2
  3. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15
    Amit,

    you should use dbi-dbd interface for connecting the perl with mysql.

    here is an example:

    #!/usr/bin/perl

    use CGI;
    use DBI;

    $q=new CGI;

    print $q->header;

    $dbh=DBI->connect('dbi:mysql:databasename','username','pwd');

    #connect to the database ..
    #enter your database name ,username and password to the connection string..

    $sql="SELECT * FROM tblname";

    print "Database Connectedn";

    $sth = $dbh->prepare($sql)
    or die "Can't prepare $sql: $dbh->errstrn";
    #pass sql query to database handle..

    $rv = $sth->execute
    or die "can't execute the query: $sth->errstrn";

    #execute your query


    if ($rv==0){
    #no rows fetched..

    print "No Recordsn";
    }else{
    #record is available in your table

    while(@row = $sth->fetchrow_array) {
    print $row[0];
    #print first column

    }
    }


    hope this may help you to connect perl with mysql.

    GOOD LUCK!!!!

    ------------------
    SR -
    shiju.dreamcenter.net
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Location
    London, England
    Posts
    251
    Rep Power
    15
    You can find out more about the Perl DBI module at http://www.symbolstone.org/technolog...DBI/index.html

    There is a very good sample chapter from the "official" DBI book, Programming the Perl DBI by Descartes & Bunce.
    http://www.amazon.com/exec/obidos/AS...621359-3369603

    Well worth buying if you're going to do a lot of this sort of thing. Look around the net, there should be a few good DBI tutorials too.

  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    2
    Rep Power
    0
    There is an excellent tutorial for beginners on this topic at this site...
    www.perl.com/pub/1999/10/DBI.html

IMN logo majestic logo threadwatch logo seochat tools logo