Home >> perldatabases >>
How to use Bind Variables?
#!/usr/bin/perl
use DBI;
my $dsn = "dbi:mysql:database=database:host=hostname:port";
my $dbuser = "tpmon";
my $dbpass = "merrill";
my $dbh = DBI->connect($dsn,$dbuser,$dbpass);
my $SEL = "SELECT e.name,e.job,d.name emp e, dept d WHERE e.deptno=d.deptno AND e.empno=? and dob=?";
my $sth = $db->prepare($SEL);
print "Enter EMPNO:";
my $empno = ;
my $dob=”19550606”;
$sth->bind_param( 1, $empno );
$sth->bind_param( 2, $dob);
$sth->execute();
The general idea here is that if the statement already exists within the Shared SQL Cache, the database doesn't need to reprocess that statement before returning a handle to the statement. It can simply reuse the information stored in the cache. This process can increase performance quite dramatically in cases where the same SQL is executed over and over again.
Perl functions
|
Perl and Databases: MySQL,Sybase Oracle, dbi
Download perl
download stable version of perl
Perl 5.10.1
|
|