Skip to content

Instantly share code, notes, and snippets.

@kiyotakagoto
Created October 14, 2011 08:46
Show Gist options
  • Select an option

  • Save kiyotakagoto/1286590 to your computer and use it in GitHub Desktop.

Select an option

Save kiyotakagoto/1286590 to your computer and use it in GitHub Desktop.
なぜか Premature end of script エラーが出る
#! /usr/bin/perl
use strict;
use warnings;
use JSON;
use CGI;
use DBI;
use Encode qw/ decode_utf8 /;
my $cgi = CGI->new;
my $table = $cgi->url_param('table');
# connect to DB
my $dbh = DBI->connect(
'dbi:mysql:dbname=hoge',
'hoge',
'hoge'
);
# create statement handler
my $sql = "select * from hoge_${table}";
my $sth = $dbh->prepare($sql);
# execute statement handler
$sth->execute();
my $container = [];
while ( my ($community_id, $community_name) = $sth->fetchrow_array ) {
push @{$container}, { $community_id => decode_utf8($community_name) };
}
# release statement handler
$sth->finish();
# release database handler
$dbh->disconnect;
$cgi->header(
-charset => 'UTF-8',
-type => 'application/json',
);
print JSON::encode_json( $container );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment