#!/usr/bin/perl use warnings; use strict; use DBI; # Gather some information from the user : print "Enter your MySQL username: "; my $username = <STDIN>; chomp $username; # remove trailing newline from Enter keypress print "Enter your MySQL password; "; my $password = <STDIN>; chomp $password; # Connect to the database my $dbh = DBI->connect("DBI:mysql:database=perl:host=localhost",$usern +ame,$password) || die "Couldn't connect to database"; print "Database connection established."; # Prepare statement my $sth = $dbh->prepare( "SELECT * FROM perl_table" ); # Send statement to database $sth->execute || die "Couldn't execute statement"; # Print out the data my @row; while ( @row = $sth->fetchrow_array() ) { print "@row \n"; } # One more thing: we need to disconnect from the database server # when we're done. $dbh->disconnect;
In reply to Re: Fetch Data from MySQL
by zentara
in thread Fetch Data from MySQL
by anu2011
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |