Perl with MySql Data Base on Linux

/////////////PERL code connectivity with MySql database ON LINUX//////////////
Here in this programme we write ip address 127.0.0.1 its a default ip address of the system.We can change it to according to our need.
#!usr/bin/perl
use DBI;
$dbh=DBI->connect("dbi:mysql:service:127.0.0.1","root","dialnet") or die "Connection Error:$DBI::errstr\n";
$sql="select * from subscription";
$sql="select * from employee";
$result=$dbh->prepare($sql);
$result->execute() or die "SQL Error:$DBI::errstr\n";
$i=0;
#while(@row=$result->fetchrow_array()) {
#print "@row\n";
#print "@row\n";

#}

@row=$result->fetchrow_array();
@time=$row[3];
print "time $time[0]\n";
$result->finish;
$dbh->disconnect(); 

/////////////////INSERT DATA IN TO A TABLE/////////////
#!usr/bin/perl
use DBI;
print "Enter employee code\n";
$code=<>;
print "Enter employee name\n";
$name=<>;
print "Enter employee address\n";
$address=<>;
print "Enter employee telephone number\n";
$number=<>;

$dbh=DBI->connect("dbi:mysql:first","root","dialnet") or die "Connection Error:$DBI::errstr\n";
$query="insert into employee values('$code','$name','$address','$number')";
$result=$dbh->prepare($query);
$result->execute or die "SQL Error:$DBI::errstr\n";

$query="select * from employee where emp_number='9898989898'";
#$query="update employee set emp_name='updated name' where emp_number='9898989898'"; 
$result=$dbh->prepare($query);
$result->execute or die "SQL Error:$DBI::errstr\n"; 
while(@row=$result->fetchrow_array()) 
{
      print "@row\n";
}

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

Comments

Popular posts from this blog

Error : DependencyManagement.dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: com.adobe.aem:uber-jar:jar:apis -> version 6.3.0 vs 6.4.0

Operators in Asterisk with Linux

ERROR Exception while handling event Sitecore.Eventing.Remote.PublishEndRemoteEventException: System.AggregateExceptionMessage: One or more exceptions occurred while processing the subscribers to the 'publish:end:remote'