First need to install
ppm install DBD::mysql
use strict; use DBI; my $host = " localhost " ; #host address my $driver = " mysql " ; # the default interface type is localhost my $database = " RUNOOB " ; # database # handle to the driver object my $dsn = " DBI:$driver:database=$database:$host " ; my $userid = " root " ; # database username my $password = " 123456 " ; # database password # Connect to database my $dbh = DBI-> connect ( $dsn , $userid , $password ) or die $DBI :: errstr; my $sth = $dbh ->prepare( " SELECT * FROM Websites " ) ; #Preprocessing SQL statement $sth ->execute(); #Execute SQL operation # Note that this part uses bound value operations # $alexa = 20; # my $sth = $dbh->prepare("SELECT name, url # FROM Websites # WHERE alexa > ?"); # $sth->execute( $alexa ) or die $DBI::errstr; # loop to output all data while ( my @row = $sth -> fetchrow_array() ) { print join('\t', @row)."\n"; } $sth->finish(); $dbh->disconnect();