programming-examples/perl/Database/Query parameter binding.pl

17 lines
464 B
Perl
Raw Normal View History

2019-11-15 12:59:38 +01:00
use DBI;
my $driver="DBI:mysql";
my $database="sample_db";
my $user="root";
my $password="";
my $host="localhost";
my $dbh = DBI->connect("$driver:$database:$host","$user","$password") or die "Can't connect: " . DBI->errstr;
$sth=$dbh->prepare("SELECT name FROM Employee where name LIKE ?") or die "Can't prepare sql statement" .
DBI->errstr;
$sth->bind_param(1, "Ch%");
$sth->execute();
$sth->dump_results();
$sth->finish();
$dbh->disconnect();