0% found this document useful (0 votes)
13 views

Perl Database

This document discusses connecting to a MySQL database from Perl, executing queries, retrieving results, and cleaning up. It explains how to connect to the database using DBI, prepare and execute queries, get the number of rows in results, display rows in a while loop, and finish and disconnect from the database.

Uploaded by

ag_krish
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Perl Database

This document discusses connecting to a MySQL database from Perl, executing queries, retrieving results, and cleaning up. It explains how to connect to the database using DBI, prepare and execute queries, get the number of rows in results, display rows in a while loop, and finish and disconnect from the database.

Uploaded by

ag_krish
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Module 2

Perl with
Database

PERL MySQL database


connectivity procedure.

Connect To Database
Execute a Query

Number of rows in result


Display Results

Cleaning Up and
Disconnect

Connect To Database

use DBI;
# The DBI interface to MySQL

$db = DBI-> connect (


"DBI:mysql:$database:$hostname
, $username, $password );

Execute a Query

query is setup using the


"prepare" method
$query = $db->prepare
("SELECT * FROM test");
Call "execute" method
$query->execute;

Number of rows in result

$numrows = $query>rows;

Display Results

while( @row = $query->


fetch_array())
{
print "$row[0]: $row[1]
";
}

Cleaning Up and
Disconnect

$query->finish;
$db->disconnect;

Connect To Database
Execute a Query

Number of rows in result


Display Results

Cleaning Up and
Disconnect

You might also like