First you need to install
PPM Install Dbd::mysql
UseStrict; UseDBI;my $host="localhost";#Host Addressmy $driver="MySQL";#interface type defaults to localhostmy $database="Runoob";#handle to the database # driver Objectmy $dsn="DBI: $driver:d atabase= $database: $host"; my $userid="Root";#Database user namemy $password="123456";#Database Password # connect to databasemy $DBH= dbi->Connect($dsn,$userid,$password) or die $DBI::Errstr;my $sth=$DBH->prepare ("SELECT * from Websites");#preprocessing SQL Statements$sth->execute ();#Execute SQL Operation # Note This section uses the bound value operation # $alexa = 20;# my $sth = $dbh->prepare ("Select name, url# from W ebsites# WHERE alexa >? "); # $sth->execute ($alexa) or Die $DBI:: errstr; # Loop out all data while(my @row=$sth-Fetchrow_array ()) { Print Join('\ t',@row)."\ n";} $sth-finish ();$DBH->disconnect ();
Perl Connect MySQL Database