By using DBI, you can easily connect to the MySQL database using Perl:
The code is as follows:
Copy the Code code as follows:
#!/bin/perl
Use DBI;
# Connect to Target DB
My $dbh = Dbi->connect ("Dbi:mysql:database=eygle;host=localhost", "username", "password", {' RaiseError ' = 1});
# Insert one row
My $rows = $dbh->do ("INSERT into Test (ID, name) VALUES (1, ' Eygle ')");
# query
My $sqr = $dbh->prepare ("Select name from Test");
$sqr->execute ();
while (my $ref = $sqr->fetchrow_hashref ()) {
Print "$ref->{' name '}n";
}
$DBH->disconnect ();
Execution Result:
Copy the Code code as follows:
[Root@eygle ~]# Perl test.cgi
Eygle
In the future, many statistics can be written directly to the MySQL database via Perl, which is much easier to operate.
http://www.bkjia.com/PHPjc/755286.html www.bkjia.com true http://www.bkjia.com/PHPjc/755286.html techarticle by using DBI, Perl can easily connect to the MySQL database: The code is as follows: Copy the code as follows: #!/bin/perl use DBI; # Connect to target DB my $dbh = Dbi-connect ("db ...