Wednesday, January 28, 2009

fetch data using Select query in perl

Here is code to fetch the data from database and display it with loop

#!/usr/bin/perl

use Mysql;

print "Content-type: text/html \n\n";

# MYSQL CONFIG VARIABLES
$host = "localhost";
$database = "store";
$tablename = "inventory";
$user = "username";
$pw = "password";

# PERL MYSQL CONNECT()
$connect = Mysql->connect($host, $database, $user, $pw);

# SELECT DB
$connect->selectdb($database);

# DEFINE A MySQL QUERY
$myquery = "SELECT * FROM $tablename";

# EXECUTE THE QUERY FUNCTION
$execute = $connect->query($myquery);

# HTML TABLE
print "


";

# FETCHROW ARRAY

while (@results = $execute->fetchrow()) {
print "";
}

print "
idproductquantity
"
.$results[0]."
"
.$results[1]."
"
.$results[2]."
";

No comments:

Post a Comment