Category Archives: Uncategorized

How to get the exact errors into error log in perl?

For that we can use a module as follows.

use CGI::Carp qw(fatalsToBrowser);

Search cpan.org for more details.

Sending mail using Perl?

#!/usr/bin/perl -w
use strict;
use CGI;
use vars qw($q);
use CGI::Carp qw(fatalsToBrowser);
use Mail::Sendmail;
use Mail::Sender;
$q = new CGI;
print $q->header();
my $mail_content=qq{
<html>
<head>
<title>Registration</title>
</head>
<body>
<p>
Test Content &nbsp;</p>
</body>
</html>

};
my $subject=”Subject”;
my %mail = (
To => “test_to\@manu.co.in”,
From=>  “test_from\@manu.co.in”,
subject=> $subject,
);
$mail{‘content-type’} = “text/html”;
$mail{Smtp} = “localhost”;
$mail{‘Message : ‘} = $mail_content ;
if (sendmail  %mail){
print qq{
<script type=”text/javascript”>
alert(“Registration success”);
</script>
};
}
else{
print qq{
<script type=”text/javascript”>
alert(“Registration failed. Please Try Again”);
</script>
};
}

How to group contents from multiple table and show in single query?

SELECT bookings_category.id AS id,bookings_category.desc_en AS room,COUNT(*) AS cnt FROM bookings_items,bookings_category WHERE bookings_category.id=bookings_items.category AND bookings_category.state=’1′ AND bookings_items.state=’1′ GROUP BY bookings_items.category;

o/p

 

Actual tables

bookings_category

bookings_items

How to update a same column in different rows with different values in single query?

UPDATE table SET `status`= CASE WHEN (id=”4″) THEN “1” ELSE “0” END;

o/p

result print screen

How to get the time from UNIX time in GMT to IST in the format ‘2013-09-24 19:16:42’?

SELECT CONVERT_TZ(FROM_UNIXTIME(1380011215),’+05:30′,’+00:00′);

 

o/p

2013-09-24 08:26:55