PERL - MySQL Connect
The MySQL module works only with the MySQL platform. We can maintain the same variables from the previous example to connect to MySQL.perlmysqlconnect.pl:
#!/usr/bin/perl # PERL MODULE use Mysql; # HTTP HEADER print "Content-type: text/html \n\n"; # CONFIG VARIABLES $host = "localhost"; $database = "store"; $tablename = "inventory"; $user = "username"; $pw = "password"; # PERL MYSQL CONNECT $connect = Mysql->connect($host, $database, $user, $pw);
PERL - MySQL listdbs()
Once PERL has established a connection we can execute any of the built in module functions. A great introductory function is the listdbs function. This function reads from the MySQL platform and places the name of each database into an array.listdbs.pl:
@databases = $connect->listdbs;
listdbs2.pl:
#!/usr/bin/perl # PERL MODULES use Mysql; # MYSQL CONFIG VARIABLES $host = "localhost"; $database = "store"; $tablename = "inventory"; $user = "username"; $pw = "password"; # PERL CONNECT() $connect = Mysql->connect($host, $database, $user, $pw); # LISTDBS() @databases = $connect->listdbs; foreach $database (@databases) { print "$database<br />"; }
0 comments:
Post a Comment