Created
October 14, 2011 08:46
-
-
Save kiyotakagoto/1286590 to your computer and use it in GitHub Desktop.
なぜか Premature end of script エラーが出る
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /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