Binding Columns : DBI « Database « Perl






Binding Columns

   

use DBI;
my $driver="DBI:mysql";
my $database="sample_db";
my $user="root";
my $host="localhost";

my $dbh = DBI->connect("$driver:database=$database;host=$host;user=$user")or die "Can't connect: " . DBI->errstr;
my $sth=$dbh->prepare("SELECT name FROM Employee") or die "Can't prepare sql statement" . DBI->errstr;

$sth->execute() or die "Can't prepare sql statement". $sth->errstr;
my($name);
$sth->bind_columns(\$name);
printf"\t%-20s%\n","Name"
while( $sth->fetch()){
     printf "   %-25s\n",$name;
}

$sth->finish();
$dbh->disconnect();

   
    
    
  








Related examples in the same category

1.Listing Currently Installed Drivers
2.Listing Valid DSNs
3.Talking with the Database
4.The connect() Method
5.Use DBI to connect to a database
6.Connect to Oracle
7.Connect to mysql
8.Available DBI Drivers and Data Sources